Rss feed for all blogs on the instance

main
Bob Mottram 2020-10-13 17:58:45 +01:00
parent a6f8364a33
commit fd2a3391ad
3 changed files with 102 additions and 16 deletions

11
blog.py
View File

@ -478,7 +478,8 @@ def htmlBlogPage(authorized: bool, session,
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,
noOfItems: int, pageNumber: int) -> str: noOfItems: int, pageNumber: int,
includeHeader: bool) -> str:
"""Returns an RSS version 2 feed containing posts """Returns an RSS version 2 feed containing posts
""" """
if ' ' in nickname or '@' in nickname or \ if ' ' in nickname or '@' in nickname or \
@ -490,7 +491,10 @@ 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, 'Blog', translate) blogRSS2 = ''
if includeHeader:
blogRSS2 = rss2Header(httpPrefix, nickname, domainFull,
'Blog', translate)
blogsIndex = baseDir + '/accounts/' + \ blogsIndex = baseDir + '/accounts/' + \
nickname + '@' + domain + '/tlblogs.index' nickname + '@' + domain + '/tlblogs.index'
@ -504,7 +508,10 @@ def htmlBlogPageRSS2(authorized: bool, session,
pageNumber) pageNumber)
if not timelineJson: if not timelineJson:
if includeHeader:
return blogRSS2 + rss2Footer() return blogRSS2 + rss2Footer()
else:
return blogRSS2
if pageNumber is not None: if pageNumber is not None:
for item in timelineJson['orderedItems']: for item in timelineJson['orderedItems']:

View File

@ -213,6 +213,8 @@ from devices import E2EEdevicesCollection
from devices import E2EEvalidDevice from devices import E2EEvalidDevice
from devices import E2EEaddDevice from devices import E2EEaddDevice
from newswire import getRSSfromDict from newswire import getRSSfromDict
from newswire import rss2Header
from newswire import rss2Footer
from newsdaemon import runNewswireWatchdog from newsdaemon import runNewswireWatchdog
from newsdaemon import runNewswireDaemon from newsdaemon import runNewswireDaemon
import os import os
@ -4228,7 +4230,8 @@ class PubServer(BaseHTTPRequestHandler):
nickname, nickname,
domain, domain,
port, port,
maxPostsInRSSFeed, 1) maxPostsInRSSFeed, 1,
True)
if msg is not None: if msg is not None:
msg = msg.encode('utf-8') msg = msg.encode('utf-8')
self._set_headers('text/xml', len(msg), self._set_headers('text/xml', len(msg),
@ -4246,6 +4249,66 @@ class PubServer(BaseHTTPRequestHandler):
path + ' ' + callingDomain) path + ' ' + callingDomain)
self._404() self._404()
def _getRSS2site(self, authorized: bool,
callingDomain: str, path: str,
baseDir: str, httpPrefix: str,
domainFull: str, port: int, proxyType: str,
translate: {},
GETstartTime, GETtimings: {},
debug: bool):
"""Returns an RSS2 feed for all blogs on this instance
"""
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 = ''
for subdir, dirs, files in os.walk(baseDir + '/accounts'):
for acct in dirs:
if '@' not in acct:
continue
if 'inbox@' in acct or 'news@' in acct:
continue
nickname = acct.split('@')[0]
domain = acct.split('@')[1]
msg += \
htmlBlogPageRSS2(authorized,
self.server.session,
baseDir,
httpPrefix,
self.server.translate,
nickname,
domain,
port,
maxPostsInRSSFeed, 1,
False)
if msg:
msg = rss2Header(httpPrefix,
'news', domainFull,
'News', translate) + msg + rss2Footer()
msg = msg.encode('utf-8')
self._set_headers('text/xml', len(msg),
None, callingDomain)
self._write(msg)
if debug:
print('Sent rss2 feed: ' +
path + ' ' + callingDomain)
self._benchmarkGETtimings(GETstartTime, GETtimings,
'sharedInbox enabled',
'blog rss2')
return
if debug:
print('Failed to get rss2 feed: ' +
path + ' ' + callingDomain)
self._404()
def _getNewswireFeed(self, authorized: bool, def _getNewswireFeed(self, authorized: bool,
callingDomain: str, path: str, callingDomain: str, path: str,
baseDir: str, httpPrefix: str, baseDir: str, httpPrefix: str,
@ -8513,6 +8576,7 @@ class PubServer(BaseHTTPRequestHandler):
# 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'):
if not self.path == '/blog/rss.xml':
self._getRSS2feed(authorized, self._getRSS2feed(authorized,
callingDomain, self.path, callingDomain, self.path,
self.server.baseDir, self.server.baseDir,
@ -8522,6 +8586,16 @@ class PubServer(BaseHTTPRequestHandler):
self.server.proxyType, self.server.proxyType,
GETstartTime, GETtimings, GETstartTime, GETtimings,
self.server.debug) self.server.debug)
else:
self._getRSS2site(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 return
self._benchmarkGETtimings(GETstartTime, GETtimings, self._benchmarkGETtimings(GETstartTime, GETtimings,

View File

@ -5508,10 +5508,15 @@ def getLeftColumnContent(baseDir: str, nickname: str, domainFull: str,
iconsDir + '/edit.png" /></a>\n' iconsDir + '/edit.png" /></a>\n'
# RSS icon # RSS icon
if nickname != 'news':
# rss feed for this account
rssUrl = httpPrefix + '://' + domainFull + \
'/blog/' + nickname + '/rss.xml'
else:
# rss feed for all accounts on the instance
rssUrl = httpPrefix + '://' + domainFull + '/blog/rss.xml'
htmlStr += \ htmlStr += \
' <a href="' + \ ' <a href="' + rssUrl + '">' + \
httpPrefix + '://' + domainFull + \
'/blog/' + nickname + '/rss.xml">' + \
'<img class="' + editImageClass + \ '<img class="' + editImageClass + \
'" loading="lazy" alt="' + \ '" loading="lazy" alt="' + \
translate['RSS feed for this site'] + \ translate['RSS feed for this site'] + \