diff options
Diffstat (limited to 'rss.py')
-rwxr-xr-x | rss.py | 52 |
1 files changed, 28 insertions, 24 deletions
@@ -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 = """<?xml version="1.0" encoding="UTF-8"?> + feed = f"""<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"> <channel> - <title>""" + title + """</title> - <link>""" + url + """</link> - <description>""" + description + """</description> - <lastBuildDate>""" + _format_date(datetime.now()) + """</lastBuildDate>""" + <title>{feed_data['title']}</title> + <link>{feed_data['url']}</link> + <description>{feed_data['description']}</description> + <lastBuildDate>{_format_date(datetime.now())}</lastBuildDate>""" - for item in content: - feed += ' <item>' - feed += ' <title><![CDATA[' + item.get('title', 'N/A') + ']]></title>' - feed += ' <link>' + item.get('url', 'N/A') + '</link>' - feed += ' <description><![CDATA[' + item.get('content', 'N/A') + ']]></description>' - if 'date' in item: - if type(item['date']) is str: - feed += ' <pubDate>' + item['date'] + '</pubDate>' + for item in feed_data["content"]: + feed += " <item>" + feed += f" <title><![CDATA[{item.get('title', 'N/A')}]]></title>" + feed += f" <link>{item.get('url', 'N/A')}</link>" + feed += f" <description><![CDATA[{item.get('content', 'N/A')}]]></description>" + if "date" in item: + if type(item["date"]) is str: + feed += f" <pubDate>{item['date']}</pubDate>" else: - feed += ' <pubDate>' + _format_date(item['date']) + '</pubDate>' - for enclosure in item.get('enclosures', []): - feed += ' <media:content url="' + enclosure + '" />' - if 'guid' in item: - feed += ' <guid>' + item['guid'] + '</guid>' - feed += ' </item>' + feed += f" <pubDate>{_format_date(item['date'])}</pubDate>" + for enclosure in item.get("enclosures", []): + feed += f" <media:content url=\"{enclosure}\" />" + if "guid" in item: + feed += f" <guid>{item['guid']}</guid>" + feed += " </item>" - feed += ' </channel>' - feed += '</rss>' + feed += " </channel>" + feed += "</rss>" return feed |