From 36893bb2087b122615b75e73786fb17704e75ffd Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Oct 2020 23:17:37 +0100 Subject: [PATCH] Function to get a list of rss feeds from file --- session.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/session.py b/session.py index 02e976c0c..b9275144d 100644 --- a/session.py +++ b/session.py @@ -13,6 +13,7 @@ import json from socket import error as SocketError import errno from datetime import datetime +from collections import OrderedDict baseDirectory = None @@ -131,7 +132,7 @@ def xml2StrToDict(xmlStr: str) -> {}: try: publishedDate = \ datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S UT") - result[str(publishedDate)] = [title, link] + result[str(publishedDate) + '+00:00'] = [title, link] parsed = True except BaseException: print('WARN: unrecognized RSS date format: ' + pubDate) @@ -188,6 +189,22 @@ def getRSS(session, url: str) -> {}: return None +def getRSSFromSubscriptions(session, subscriptionsFilename: str) -> {}: + """Gets rss feeds as a dictionary from a list of feeds stored in a file + """ + if not os.path.isfile(subscriptionsFilename): + return {} + + rssFeed = [] + with open(subscriptionsFilename, 'r') as fp: + rssFeed = fp.readlines() + result = {} + for url in rssFeed: + result = dict(result.items() + getRSS(session, url).items()) + sortedResult = OrderedDict(sorted(result.items(), reverse=False)) + return sortedResult + + def postJson(session, postJsonObject: {}, federationList: [], inboxUrl: str, headers: {}) -> str: """Post a json message to the inbox of another person