Skip to content

Commit aeb0bae

Browse files
authored
feat: add GUID to RSS feed
1 parent baafd47 commit aeb0bae

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

convert_json.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import xml.etree.ElementTree as ET
77
from xml.dom import minidom
88

9+
910
JSON_PATH = "emails.json"
1011
RSS_PATH = "emails.rss"
1112

@@ -46,29 +47,32 @@ def rss_item(title: str | None = None,
4647
# Make sure months are processed correctly when there's some inconsistency
4748
# https://docs.python.org/3/library/datetime.html#format-codes
4849
# 09:00:00 EST is set as default for simplicity
49-
fmt_date = parser.parse(pubDate).strftime("%a %d %b %Y 09:00:00 EST")
50-
item[-1].text = fmt_date
50+
item[-1].text = parser.parse(pubDate).strftime("%a %d %b %Y 09:00:00 EST")
51+
52+
# Make GUID just YYYYMMDD for simplicity
53+
# RSS specification https://validator.w3.org/feed/docs/warning/MissingGuid.html
54+
item.append(ET.Element("guid"))
55+
item[-1].text = parser.parse(pubDate).strftime("%Y%m%d")
5156

5257
return item
5358

5459

5560
with open(JSON_PATH, 'rb') as emails_json_file:
5661
json_data: dict = json.load(emails_json_file)
5762

58-
5963
tree = ET.ElementTree(ET.Element("rss", {"version": "2.0"}))
6064

6165
root = tree.getroot()
6266

6367
root.append(ET.Element("channel"))
6468
channel = root[0]
6569

70+
# Setup RSS metadata specifications
6671
channel.extend([
6772
ET.Element("title"),
6873
ET.Element("link"),
6974
ET.Element("description"),
7075
])
71-
7276
channel[0].text = RSS_CHANNEL_TITLE
7377
channel[1].text = RSS_CHANNEL_LINK
7478
channel[2].text = RSS_CHANNEL_DESCRIPTION
@@ -109,5 +113,5 @@ def rss_item(title: str | None = None,
109113
with open(RSS_PATH, 'w') as emails_rss_file:
110114
emails_rss_file.write(rss)
111115

112-
# verify RSS (XML) is parse-able
116+
# Verify RSS (XML) is parse-able
113117
ET.ElementTree().parse(RSS_PATH)

0 commit comments

Comments
 (0)