From b526cc68929250a7f71ff21ed8410ffd8db87a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Thu, 29 Jul 2021 10:48:55 +0200 Subject: Format using black --- rss.py | 56 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 13 deletions(-) (limited to 'rss.py') diff --git a/rss.py b/rss.py index 8fbf6a2..2f67723 100755 --- a/rss.py +++ b/rss.py @@ -3,6 +3,7 @@ from datetime import datetime from typing import List + def _format_date(dt): """convert a datetime into an RFC 822 formatted date Input date must be in GMT. @@ -15,12 +16,39 @@ def _format_date(dt): # Isn't there a standard way to do this for Python? The # rfc822 and email.Utils modules assume a timestamp. The # following is based on the rfc822 module. + weekdays = [ + "Mon", + "Tue", + "Wed", + "Thu", + "Fri", + "Sat", + "Sun", + ] + months = [ + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec", + ] return "%s, %02d %s %04d %02d:%02d:%02d GMT" % ( - ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][dt.weekday()], - dt.day, - ["Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][dt.month-1], - dt.year, dt.hour, dt.minute, dt.second) + weekdays[dt.weekday()], + dt.day, + months[dt.month - 1], + dt.year, + dt.hour, + dt.minute, + dt.second, + ) + class RSSItem: title: str @@ -40,12 +68,12 @@ class RSSFeed: def buildRSS(feed_data: RSSFeed): """ - feed_data = { - title, url, description, - content = [{ - title, url, content, date, [enclosures], guid - }] - } + feed_data = { + title, url, description, + content = [{ + title, url, content, date, [enclosures], guid + }] + } """ feed = f""" @@ -60,14 +88,16 @@ def buildRSS(feed_data: RSSFeed): feed += " " feed += f" <![CDATA[{item.get('title', 'N/A')}]]>" feed += f" {item.get('url', 'N/A')}" - feed += f" " + feed += ( + f" " + ) if "date" in item: if type(item["date"]) is str: feed += f" {item['date']}" else: feed += f" {_format_date(item['date'])}" for enclosure in item.get("enclosures", []): - feed += f" " + feed += f' ' if "guid" in item: feed += f" {item['guid']}" feed += " " -- cgit v1.2.3