summaryrefslogtreecommitdiff
path: root/rss.py
diff options
context:
space:
mode:
Diffstat (limited to 'rss.py')
-rwxr-xr-xrss.py56
1 files changed, 43 insertions, 13 deletions
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"""<?xml version="1.0" encoding="UTF-8"?>
@@ -60,14 +88,16 @@ def buildRSS(feed_data: RSSFeed):
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>"
+ 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 += f" <pubDate>{_format_date(item['date'])}</pubDate>"
for enclosure in item.get("enclosures", []):
- feed += f" <media:content url=\"{enclosure}\" />"
+ feed += f' <media:content url="{enclosure}" />'
if "guid" in item:
feed += f" <guid>{item['guid']}</guid>"
feed += " </item>"