diff --git a/blog.py b/blog.py
index 0d9c0aedd..8a1251298 100644
--- a/blog.py
+++ b/blog.py
@@ -20,6 +20,8 @@ from utils import getDomainFromActor
from utils import locatePost
from utils import loadJson
from posts import createBlogsTimeline
+from newswire import rss2Header
+from newswire import rss2Footer
def noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
@@ -473,23 +475,6 @@ def htmlBlogPage(authorized: bool, session,
return None
-def rss2Header(httpPrefix: str,
- nickname: str, domainFull: str, translate: {}) -> str:
- rssStr = ""
- rssStr += ""
- rssStr += ''
- rssStr += ' ' + translate['Blog'] + ''
- rssStr += ' ' + httpPrefix + '://' + domainFull + \
- '/users/' + nickname + '/rss.xml' + ''
- return rssStr
-
-
-def rss2Footer() -> str:
- rssStr = ''
- rssStr += ''
- return rssStr
-
-
def htmlBlogPageRSS2(authorized: bool, session,
baseDir: str, httpPrefix: str, translate: {},
nickname: str, domain: str, port: int,
@@ -505,7 +490,7 @@ def htmlBlogPageRSS2(authorized: bool, session,
if port != 80 and port != 443:
domainFull = domain + ':' + str(port)
- blogRSS2 = rss2Header(httpPrefix, nickname, domainFull, translate)
+ blogRSS2 = rss2Header(httpPrefix, nickname, domainFull, 'Blog', translate)
blogsIndex = baseDir + '/accounts/' + \
nickname + '@' + domain + '/tlblogs.index'
diff --git a/daemon.py b/daemon.py
index eee271584..dabaefb56 100644
--- a/daemon.py
+++ b/daemon.py
@@ -203,6 +203,7 @@ from followingCalendar import removePersonFromCalendar
from devices import E2EEdevicesCollection
from devices import E2EEvalidDevice
from devices import E2EEaddDevice
+from newswire import getRSSfromDict
import os
@@ -3954,6 +3955,42 @@ class PubServer(BaseHTTPRequestHandler):
path + ' ' + callingDomain)
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,
callingDomain: str, path: str,
baseDir: str, httpPrefix: str,
@@ -7813,6 +7850,18 @@ class PubServer(BaseHTTPRequestHandler):
self._benchmarkGETtimings(GETstartTime, GETtimings,
'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
if self.path.startswith('/blog/') and \
self.path.endswith('/rss.xml'):
@@ -11022,6 +11071,9 @@ def runDaemon(blogsInstance: bool, mediaInstance: bool,
httpd.unitTest = unitTest
httpd.YTReplacementDomain = YTReplacementDomain
+ # newswire storing rss feeds
+ httpd.newswire = {}
+
# 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
httpd.blocklistUpdateCtr = 0
diff --git a/newswire.py b/newswire.py
index 07af875a7..d295b1273 100644
--- a/newswire.py
+++ b/newswire.py
@@ -14,6 +14,31 @@ from datetime import datetime
from collections import OrderedDict
+def rss2Header(httpPrefix: str,
+ nickname: str, domainFull: str,
+ title: str, translate: {}) -> str:
+ rssStr = ""
+ rssStr += ""
+ rssStr += ''
+ if title.startswith('News'):
+ rssStr += ' Newswire'
+ else:
+ rssStr += ' ' + translate[title] + ''
+ if title.startswith('News'):
+ rssStr += ' ' + httpPrefix + '://' + domainFull + \
+ '/newswire.xml' + ''
+ else:
+ rssStr += ' ' + httpPrefix + '://' + domainFull + \
+ '/users/' + nickname + '/rss.xml' + ''
+ return rssStr
+
+
+def rss2Footer() -> str:
+ rssStr = ''
+ rssStr += ''
+ return rssStr
+
+
def xml2StrToDict(xmlStr: str) -> {}:
"""Converts an xml 2.0 string to a dictionary
"""
@@ -109,7 +134,28 @@ def getRSS(session, url: str) -> {}:
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 += '- \n'
+ rssStr += ' ' + fields[0] + '\n'
+ rssStr += ' ' + fields[1] + '\n'
+ pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
+ rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
+ rssStr += ' ' + rssDateStr + '\n'
+ rssStr += '
\n'
+ rssStr += rss2Footer()
+ return rssStr
+
+
+def getDictFromNewswire(session, baseDir: str) -> {}:
"""Gets rss feeds as a dictionary from newswire file
"""
subscriptionsFilename = baseDir + '/accounts/newswire.txt'
diff --git a/translations/ar.json b/translations/ar.json
index 0228d7e95..ae92a954a 100644
--- a/translations/ar.json
+++ b/translations/ar.json
@@ -295,5 +295,6 @@
"Right column image": "صورة العمود الأيمن",
"RSS feed for this site": "تغذية RSS لهذا الموقع",
"Edit newswire": "تحرير الأخبار",
- "Add RSS feed links below.": "إضافة روابط تغذية RSS أدناه."
+ "Add RSS feed links below.": "إضافة روابط تغذية RSS أدناه.",
+ "Newswire RSS Feed": "Newswire موجز RSS"
}
diff --git a/translations/ca.json b/translations/ca.json
index 131d19aeb..5671b1dbc 100644
--- a/translations/ca.json
+++ b/translations/ca.json
@@ -295,5 +295,6 @@
"Right column image": "Imatge de la columna dreta",
"RSS feed for this site": "Feed RSS per a aquest lloc",
"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"
}
diff --git a/translations/cy.json b/translations/cy.json
index 4a09e9eaa..b5f824854 100644
--- a/translations/cy.json
+++ b/translations/cy.json
@@ -295,5 +295,6 @@
"Right column image": "Delwedd colofn dde",
"RSS feed for this site": "Porthiant RSS ar gyfer y wefan hon",
"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"
}
diff --git a/translations/de.json b/translations/de.json
index b6ae2ee36..00fad6c8a 100644
--- a/translations/de.json
+++ b/translations/de.json
@@ -295,5 +295,6 @@
"Right column image": "Bild in der rechten Spalte",
"RSS feed for this site": "RSS-Feed für diese Site",
"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"
}
diff --git a/translations/en.json b/translations/en.json
index 68d59aea7..2a12fc9db 100644
--- a/translations/en.json
+++ b/translations/en.json
@@ -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."
+ "Add RSS feed links below.": "Add RSS feed links below.",
+ "Newswire RSS Feed": "Newswire RSS Feed"
}
diff --git a/translations/es.json b/translations/es.json
index 5c0bb8e88..2ff5870f5 100644
--- a/translations/es.json
+++ b/translations/es.json
@@ -295,5 +295,6 @@
"Right column image": "Imagen de la columna derecha",
"RSS feed for this site": "Fuente RSS para este sitio",
"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"
}
diff --git a/translations/fr.json b/translations/fr.json
index d462555d0..11dec422b 100644
--- a/translations/fr.json
+++ b/translations/fr.json
@@ -295,5 +295,6 @@
"Right column image": "Image de la colonne de droite",
"RSS feed for this site": "Flux RSS de ce site",
"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"
}
diff --git a/translations/ga.json b/translations/ga.json
index 6fdfb59dd..a08ecd81c 100644
--- a/translations/ga.json
+++ b/translations/ga.json
@@ -295,5 +295,6 @@
"Right column image": "Íomhá colún ar dheis",
"RSS feed for this site": "Fotha RSS don láithreán seo",
"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"
}
diff --git a/translations/hi.json b/translations/hi.json
index e5d851f73..4caac27f1 100644
--- a/translations/hi.json
+++ b/translations/hi.json
@@ -295,5 +295,6 @@
"Right column image": "राइट कॉलम छवि",
"RSS feed for this site": "इस साइट के लिए आरएसएस फ़ीड",
"Edit newswire": "नवांश संपादित करें",
- "Add RSS feed links below.": "नीचे आरएसएस फ़ीड लिंक जोड़ें।"
+ "Add RSS feed links below.": "नीचे आरएसएस फ़ीड लिंक जोड़ें।",
+ "Newswire RSS Feed": "Newswire RSS फ़ीड"
}
diff --git a/translations/it.json b/translations/it.json
index 2e08cba0a..32008810f 100644
--- a/translations/it.json
+++ b/translations/it.json
@@ -295,5 +295,6 @@
"Right column image": "Immagine della colonna di destra",
"RSS feed for this site": "Feed RSS per questo sito",
"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"
}
diff --git a/translations/ja.json b/translations/ja.json
index 51c53b7ae..108f36f04 100644
--- a/translations/ja.json
+++ b/translations/ja.json
@@ -295,5 +295,6 @@
"Right column image": "右の列の画像",
"RSS feed for this site": "このサイトのRSSフィード",
"Edit newswire": "ニュースワイヤーを編集",
- "Add RSS feed links below.": "以下にRSSフィードリンクを追加します。"
+ "Add RSS feed links below.": "以下にRSSフィードリンクを追加します。",
+ "Newswire RSS Feed": "NewswireRSSフィード"
}
diff --git a/translations/oc.json b/translations/oc.json
index 00ad53ffe..2a7e4d9f1 100644
--- a/translations/oc.json
+++ b/translations/oc.json
@@ -291,5 +291,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."
+ "Add RSS feed links below.": "Add RSS feed links below.",
+ "Newswire RSS Feed": "Newswire RSS Feed"
}
diff --git a/translations/pt.json b/translations/pt.json
index e7baec2ec..97df10f8c 100644
--- a/translations/pt.json
+++ b/translations/pt.json
@@ -295,5 +295,6 @@
"Right column image": "Imagem da coluna direita",
"RSS feed for this site": "Feed RSS para este site",
"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"
}
diff --git a/translations/ru.json b/translations/ru.json
index dd0cf04d9..f91883dac 100644
--- a/translations/ru.json
+++ b/translations/ru.json
@@ -295,5 +295,6 @@
"Right column image": "Изображение в правом столбце",
"RSS feed for this site": "RSS-канал для этого сайта",
"Edit newswire": "Редактировать ленту новостей",
- "Add RSS feed links below.": "Добавьте ссылки на RSS-канал ниже."
+ "Add RSS feed links below.": "Добавьте ссылки на RSS-канал ниже.",
+ "Newswire RSS Feed": "Лента новостей RSS"
}
diff --git a/translations/zh.json b/translations/zh.json
index 32f57294f..c9f2aa9a7 100644
--- a/translations/zh.json
+++ b/translations/zh.json
@@ -295,5 +295,6 @@
"Right column image": "右栏图片",
"RSS feed for this site": "该站点的RSS feed",
"Edit newswire": "编辑新闻专线",
- "Add RSS feed links below.": "在下面添加RSS feed链接。"
+ "Add RSS feed links below.": "在下面添加RSS feed链接。",
+ "Newswire RSS Feed": "Newswire RSS提要"
}
diff --git a/webinterface.py b/webinterface.py
index f0f96e0fd..a867e38c6 100644
--- a/webinterface.py
+++ b/webinterface.py
@@ -5387,6 +5387,14 @@ def getRightColumnContent(baseDir: str, nickname: str, domainFull: str,
translate['Edit newswire'] + '" src="/' + \
iconsDir + '/edit.png" />\n'
+ htmlStr += \
+ ' ' + \
+ '\n'
+
if editImageClass == 'rightColEdit':
htmlStr += ' \n'
else: