From 93f3613dab38125d9ae7d5e74498c5395ac80ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Sun, 9 May 2021 20:13:08 +0200 Subject: Unify method returns / return RSS object --- rss.py | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'rss.py') diff --git a/rss.py b/rss.py index 66ffb35..f11a956 100755 --- a/rss.py +++ b/rss.py @@ -21,36 +21,40 @@ def _format_date(dt): "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][dt.month-1], dt.year, dt.hour, dt.minute, dt.second) -def buildRSS(title, url, description, content): +def buildRSS(feed_data): """ - Feed basic info: title, url, descriptions - Content: List[Dict{title, url, content, date, enclosures, guid}] + feed_data = { + title, url, description, + content = [{ + title, url, content, date, [enclosures], guid + }] + } """ - feed = """ + feed = f""" - """ + title + """ - """ + url + """ - """ + description + """ - """ + _format_date(datetime.now()) + """""" + {feed_data['title']} + {feed_data['url']} + {feed_data['description']} + {_format_date(datetime.now())}""" - for item in content: - feed += ' ' - feed += ' <![CDATA[' + item.get('title', 'N/A') + ']]>' - feed += ' ' + item.get('url', 'N/A') + '' - feed += ' ' - if 'date' in item: - if type(item['date']) is str: - feed += ' ' + item['date'] + '' + for item in feed_data["content"]: + feed += " " + feed += f" <![CDATA[{item.get('title', 'N/A')}]]>" + feed += f" {item.get('url', 'N/A')}" + feed += f" " + if "date" in item: + if type(item["date"]) is str: + feed += f" {item['date']}" else: - feed += ' ' + _format_date(item['date']) + '' - for enclosure in item.get('enclosures', []): - feed += ' ' - if 'guid' in item: - feed += ' ' + item['guid'] + '' - feed += ' ' + feed += f" {_format_date(item['date'])}" + for enclosure in item.get("enclosures", []): + feed += f" " + if "guid" in item: + feed += f" {item['guid']}" + feed += " " - feed += ' ' - feed += '' + feed += " " + feed += "" return feed -- cgit v1.2.3