Newswire rss feed

merge-requests/8/head
Bob Mottram 2020-10-04 13:29:07 +01:00
parent 3c19ab692d
commit aed4cfcbf6
19 changed files with 140 additions and 34 deletions

21
blog.py
View File

@ -20,6 +20,8 @@ from utils import getDomainFromActor
from utils import locatePost from utils import locatePost
from utils import loadJson from utils import loadJson
from posts import createBlogsTimeline from posts import createBlogsTimeline
from newswire import rss2Header
from newswire import rss2Footer
def noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {}, def noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
@ -473,23 +475,6 @@ def htmlBlogPage(authorized: bool, session,
return None return None
def rss2Header(httpPrefix: str,
nickname: str, domainFull: str, translate: {}) -> str:
rssStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
rssStr += "<rss version=\"2.0\">"
rssStr += '<channel>'
rssStr += ' <title>' + translate['Blog'] + '</title>'
rssStr += ' <link>' + httpPrefix + '://' + domainFull + \
'/users/' + nickname + '/rss.xml' + '</link>'
return rssStr
def rss2Footer() -> str:
rssStr = '</channel>'
rssStr += '</rss>'
return rssStr
def htmlBlogPageRSS2(authorized: bool, session, def htmlBlogPageRSS2(authorized: bool, session,
baseDir: str, httpPrefix: str, translate: {}, baseDir: str, httpPrefix: str, translate: {},
nickname: str, domain: str, port: int, nickname: str, domain: str, port: int,
@ -505,7 +490,7 @@ def htmlBlogPageRSS2(authorized: bool, session,
if port != 80 and port != 443: if port != 80 and port != 443:
domainFull = domain + ':' + str(port) domainFull = domain + ':' + str(port)
blogRSS2 = rss2Header(httpPrefix, nickname, domainFull, translate) blogRSS2 = rss2Header(httpPrefix, nickname, domainFull, 'Blog', translate)
blogsIndex = baseDir + '/accounts/' + \ blogsIndex = baseDir + '/accounts/' + \
nickname + '@' + domain + '/tlblogs.index' nickname + '@' + domain + '/tlblogs.index'

View File

@ -203,6 +203,7 @@ from followingCalendar import removePersonFromCalendar
from devices import E2EEdevicesCollection from devices import E2EEdevicesCollection
from devices import E2EEvalidDevice from devices import E2EEvalidDevice
from devices import E2EEaddDevice from devices import E2EEaddDevice
from newswire import getRSSfromDict
import os import os
@ -3954,6 +3955,42 @@ class PubServer(BaseHTTPRequestHandler):
path + ' ' + callingDomain) path + ' ' + callingDomain)
self._404() self._404()
def _getNewswireFeed(self, authorized: bool,
callingDomain: str, path: str,
baseDir: str, httpPrefix: str,
domain: str, port: int, proxyType: str,
GETstartTime, GETtimings: {},
debug: bool):
"""Returns the newswire feed
"""
if not self.server.session:
print('Starting new session during RSS request')
self.server.session = \
createSession(proxyType)
if not self.server.session:
print('ERROR: GET failed to create session ' +
'during RSS request')
self._404()
return
msg = getRSSfromDict(self.server.baseDir, self.server.newswire,
self.server.httpPrefix,
self.server.domainFull,
'Newswire', self.server.translate)
if msg:
msg = msg.encode('utf-8')
self._set_headers('text/xml', len(msg),
None, callingDomain)
self._write(msg)
if debug:
print('Sent rss2 newswire feed: ' +
path + ' ' + callingDomain)
return
if debug:
print('Failed to get rss2 newswire feed: ' +
path + ' ' + callingDomain)
self._404()
def _getRSS3feed(self, authorized: bool, def _getRSS3feed(self, authorized: bool,
callingDomain: str, path: str, callingDomain: str, path: str,
baseDir: str, httpPrefix: str, baseDir: str, httpPrefix: str,
@ -7813,6 +7850,18 @@ class PubServer(BaseHTTPRequestHandler):
self._benchmarkGETtimings(GETstartTime, GETtimings, self._benchmarkGETtimings(GETstartTime, GETtimings,
'fonts', 'sharedInbox enabled') 'fonts', 'sharedInbox enabled')
if self.path == '/newswire.xml':
self._getNewswireFeed(authorized,
callingDomain, self.path,
self.server.baseDir,
self.server.httpPrefix,
self.server.domain,
self.server.port,
self.server.proxyType,
GETstartTime, GETtimings,
self.server.debug)
return
# RSS 2.0 # RSS 2.0
if self.path.startswith('/blog/') and \ if self.path.startswith('/blog/') and \
self.path.endswith('/rss.xml'): self.path.endswith('/rss.xml'):
@ -11022,6 +11071,9 @@ def runDaemon(blogsInstance: bool, mediaInstance: bool,
httpd.unitTest = unitTest httpd.unitTest = unitTest
httpd.YTReplacementDomain = YTReplacementDomain httpd.YTReplacementDomain = YTReplacementDomain
# newswire storing rss feeds
httpd.newswire = {}
# This counter is used to update the list of blocked domains in memory. # This counter is used to update the list of blocked domains in memory.
# It helps to avoid touching the disk and so improves flooding resistance # It helps to avoid touching the disk and so improves flooding resistance
httpd.blocklistUpdateCtr = 0 httpd.blocklistUpdateCtr = 0

View File

@ -14,6 +14,31 @@ from datetime import datetime
from collections import OrderedDict from collections import OrderedDict
def rss2Header(httpPrefix: str,
nickname: str, domainFull: str,
title: str, translate: {}) -> str:
rssStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
rssStr += "<rss version=\"2.0\">"
rssStr += '<channel>'
if title.startswith('News'):
rssStr += ' <title>Newswire</title>'
else:
rssStr += ' <title>' + translate[title] + '</title>'
if title.startswith('News'):
rssStr += ' <link>' + httpPrefix + '://' + domainFull + \
'/newswire.xml' + '</link>'
else:
rssStr += ' <link>' + httpPrefix + '://' + domainFull + \
'/users/' + nickname + '/rss.xml' + '</link>'
return rssStr
def rss2Footer() -> str:
rssStr = '</channel>'
rssStr += '</rss>'
return rssStr
def xml2StrToDict(xmlStr: str) -> {}: def xml2StrToDict(xmlStr: str) -> {}:
"""Converts an xml 2.0 string to a dictionary """Converts an xml 2.0 string to a dictionary
""" """
@ -109,7 +134,28 @@ def getRSS(session, url: str) -> {}:
return None return None
def getRSSFromNewswire(session, baseDir: str) -> {}: def getRSSfromDict(baseDir: str, newswire: {},
httpPrefix: str, domainFull: str,
title: str, translate: {}) -> str:
"""Returns an rss feed from the current newswire dict.
This allows other instances to subscribe to the same newswire
"""
rssStr = rss2Header(httpPrefix,
None, domainFull,
'Newswire', translate)
for published, fields in newswire.items():
rssStr += '<item>\n'
rssStr += ' <title>' + fields[0] + '</title>\n'
rssStr += ' <link>' + fields[1] + '</link>\n'
pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
rssStr += ' <pubDate>' + rssDateStr + '</pubDate>\n'
rssStr += '</item>\n'
rssStr += rss2Footer()
return rssStr
def getDictFromNewswire(session, baseDir: str) -> {}:
"""Gets rss feeds as a dictionary from newswire file """Gets rss feeds as a dictionary from newswire file
""" """
subscriptionsFilename = baseDir + '/accounts/newswire.txt' subscriptionsFilename = baseDir + '/accounts/newswire.txt'

View File

@ -295,5 +295,6 @@
"Right column image": "صورة العمود الأيمن", "Right column image": "صورة العمود الأيمن",
"RSS feed for this site": "تغذية RSS لهذا الموقع", "RSS feed for this site": "تغذية RSS لهذا الموقع",
"Edit newswire": "تحرير الأخبار", "Edit newswire": "تحرير الأخبار",
"Add RSS feed links below.": "إضافة روابط تغذية RSS أدناه." "Add RSS feed links below.": "إضافة روابط تغذية RSS أدناه.",
"Newswire RSS Feed": "Newswire موجز RSS"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "Imatge de la columna dreta", "Right column image": "Imatge de la columna dreta",
"RSS feed for this site": "Feed RSS per a aquest lloc", "RSS feed for this site": "Feed RSS per a aquest lloc",
"Edit newswire": "Editeu newswire", "Edit newswire": "Editeu newswire",
"Add RSS feed links below.": "Afegiu enllaços de canals RSS a continuació." "Add RSS feed links below.": "Afegiu enllaços de canals RSS a continuació.",
"Newswire RSS Feed": "Feed RSS de Newswire"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "Delwedd colofn dde", "Right column image": "Delwedd colofn dde",
"RSS feed for this site": "Porthiant RSS ar gyfer y wefan hon", "RSS feed for this site": "Porthiant RSS ar gyfer y wefan hon",
"Edit newswire": "Golygu newyddion", "Edit newswire": "Golygu newyddion",
"Add RSS feed links below.": "Ychwanegwch ddolenni porthiant RSS isod." "Add RSS feed links below.": "Ychwanegwch ddolenni porthiant RSS isod.",
"Newswire RSS Feed": "Newswire RSS Feed"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "Bild in der rechten Spalte", "Right column image": "Bild in der rechten Spalte",
"RSS feed for this site": "RSS-Feed für diese Site", "RSS feed for this site": "RSS-Feed für diese Site",
"Edit newswire": "Newswire bearbeiten", "Edit newswire": "Newswire bearbeiten",
"Add RSS feed links below.": "Fügen Sie unten RSS-Feed-Links hinzu." "Add RSS feed links below.": "Fügen Sie unten RSS-Feed-Links hinzu.",
"Newswire RSS Feed": "Newswire RSS Feed"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "Right column image", "Right column image": "Right column image",
"RSS feed for this site": "RSS feed for this site", "RSS feed for this site": "RSS feed for this site",
"Edit newswire": "Edit newswire", "Edit newswire": "Edit newswire",
"Add RSS feed links below.": "Add RSS feed links below." "Add RSS feed links below.": "Add RSS feed links below.",
"Newswire RSS Feed": "Newswire RSS Feed"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "Imagen de la columna derecha", "Right column image": "Imagen de la columna derecha",
"RSS feed for this site": "Fuente RSS para este sitio", "RSS feed for this site": "Fuente RSS para este sitio",
"Edit newswire": "Editar newswire", "Edit newswire": "Editar newswire",
"Add RSS feed links below.": "Agregue los enlaces de fuentes RSS a continuación." "Add RSS feed links below.": "Agregue los enlaces de fuentes RSS a continuación.",
"Newswire RSS Feed": "Canal RSS de Newswire"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "Image de la colonne de droite", "Right column image": "Image de la colonne de droite",
"RSS feed for this site": "Flux RSS de ce site", "RSS feed for this site": "Flux RSS de ce site",
"Edit newswire": "Modifier le fil d'actualité", "Edit newswire": "Modifier le fil d'actualité",
"Add RSS feed links below.": "Ajoutez des liens de flux RSS ci-dessous." "Add RSS feed links below.": "Ajoutez des liens de flux RSS ci-dessous.",
"Newswire RSS Feed": "Flux RSS de Newswire"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "Íomhá colún ar dheis", "Right column image": "Íomhá colún ar dheis",
"RSS feed for this site": "Fotha RSS don láithreán seo", "RSS feed for this site": "Fotha RSS don láithreán seo",
"Edit newswire": "Cuir sreang nuachta in eagar", "Edit newswire": "Cuir sreang nuachta in eagar",
"Add RSS feed links below.": "Cuir naisc beatha RSS thíos." "Add RSS feed links below.": "Cuir naisc beatha RSS thíos.",
"Newswire RSS Feed": "Newswire RSS Feed"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "राइट कॉलम छवि", "Right column image": "राइट कॉलम छवि",
"RSS feed for this site": "इस साइट के लिए आरएसएस फ़ीड", "RSS feed for this site": "इस साइट के लिए आरएसएस फ़ीड",
"Edit newswire": "नवांश संपादित करें", "Edit newswire": "नवांश संपादित करें",
"Add RSS feed links below.": "नीचे आरएसएस फ़ीड लिंक जोड़ें।" "Add RSS feed links below.": "नीचे आरएसएस फ़ीड लिंक जोड़ें।",
"Newswire RSS Feed": "Newswire RSS फ़ीड"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "Immagine della colonna di destra", "Right column image": "Immagine della colonna di destra",
"RSS feed for this site": "Feed RSS per questo sito", "RSS feed for this site": "Feed RSS per questo sito",
"Edit newswire": "Modifica newswire", "Edit newswire": "Modifica newswire",
"Add RSS feed links below.": "Aggiungi i link ai feed RSS di seguito." "Add RSS feed links below.": "Aggiungi i link ai feed RSS di seguito.",
"Newswire RSS Feed": "Feed RSS di Newswire"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "右の列の画像", "Right column image": "右の列の画像",
"RSS feed for this site": "このサイトのRSSフィード", "RSS feed for this site": "このサイトのRSSフィード",
"Edit newswire": "ニュースワイヤーを編集", "Edit newswire": "ニュースワイヤーを編集",
"Add RSS feed links below.": "以下にRSSフィードリンクを追加します。" "Add RSS feed links below.": "以下にRSSフィードリンクを追加します。",
"Newswire RSS Feed": "NewswireRSSフィード"
} }

View File

@ -291,5 +291,6 @@
"Right column image": "Right column image", "Right column image": "Right column image",
"RSS feed for this site": "RSS feed for this site", "RSS feed for this site": "RSS feed for this site",
"Edit newswire": "Edit newswire", "Edit newswire": "Edit newswire",
"Add RSS feed links below.": "Add RSS feed links below." "Add RSS feed links below.": "Add RSS feed links below.",
"Newswire RSS Feed": "Newswire RSS Feed"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "Imagem da coluna direita", "Right column image": "Imagem da coluna direita",
"RSS feed for this site": "Feed RSS para este site", "RSS feed for this site": "Feed RSS para este site",
"Edit newswire": "Editar notícias", "Edit newswire": "Editar notícias",
"Add RSS feed links below.": "Adicione links de feed RSS abaixo." "Add RSS feed links below.": "Adicione links de feed RSS abaixo.",
"Newswire RSS Feed": "Feed RSS da Newswire"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "Изображение в правом столбце", "Right column image": "Изображение в правом столбце",
"RSS feed for this site": "RSS-канал для этого сайта", "RSS feed for this site": "RSS-канал для этого сайта",
"Edit newswire": "Редактировать ленту новостей", "Edit newswire": "Редактировать ленту новостей",
"Add RSS feed links below.": "Добавьте ссылки на RSS-канал ниже." "Add RSS feed links below.": "Добавьте ссылки на RSS-канал ниже.",
"Newswire RSS Feed": "Лента новостей RSS"
} }

View File

@ -295,5 +295,6 @@
"Right column image": "右栏图片", "Right column image": "右栏图片",
"RSS feed for this site": "该站点的RSS feed", "RSS feed for this site": "该站点的RSS feed",
"Edit newswire": "编辑新闻专线", "Edit newswire": "编辑新闻专线",
"Add RSS feed links below.": "在下面添加RSS feed链接。" "Add RSS feed links below.": "在下面添加RSS feed链接。",
"Newswire RSS Feed": "Newswire RSS提要"
} }

View File

@ -5387,6 +5387,14 @@ def getRightColumnContent(baseDir: str, nickname: str, domainFull: str,
translate['Edit newswire'] + '" src="/' + \ translate['Edit newswire'] + '" src="/' + \
iconsDir + '/edit.png" /></a>\n' iconsDir + '/edit.png" /></a>\n'
htmlStr += \
' <a href="/newswire.xml">' + \
'<img class="' + editImageClass + \
'" loading="lazy" alt="' + \
translate['Newswire RSS Feed'] + '" title="' + \
translate['Newswire RSS Feed'] + '" src="/' + \
iconsDir + '/rss.png" /></a>\n'
if editImageClass == 'rightColEdit': if editImageClass == 'rightColEdit':
htmlStr += ' </center>\n' htmlStr += ' </center>\n'
else: else: