|
6 | 6 | import xml.etree.ElementTree as ET |
7 | 7 | from xml.dom import minidom |
8 | 8 |
|
| 9 | + |
9 | 10 | JSON_PATH = "emails.json" |
10 | 11 | RSS_PATH = "emails.rss" |
11 | 12 |
|
@@ -46,29 +47,32 @@ def rss_item(title: str | None = None, |
46 | 47 | # Make sure months are processed correctly when there's some inconsistency |
47 | 48 | # https://docs.python.org/3/library/datetime.html#format-codes |
48 | 49 | # 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") |
51 | 56 |
|
52 | 57 | return item |
53 | 58 |
|
54 | 59 |
|
55 | 60 | with open(JSON_PATH, 'rb') as emails_json_file: |
56 | 61 | json_data: dict = json.load(emails_json_file) |
57 | 62 |
|
58 | | - |
59 | 63 | tree = ET.ElementTree(ET.Element("rss", {"version": "2.0"})) |
60 | 64 |
|
61 | 65 | root = tree.getroot() |
62 | 66 |
|
63 | 67 | root.append(ET.Element("channel")) |
64 | 68 | channel = root[0] |
65 | 69 |
|
| 70 | +# Setup RSS metadata specifications |
66 | 71 | channel.extend([ |
67 | 72 | ET.Element("title"), |
68 | 73 | ET.Element("link"), |
69 | 74 | ET.Element("description"), |
70 | 75 | ]) |
71 | | - |
72 | 76 | channel[0].text = RSS_CHANNEL_TITLE |
73 | 77 | channel[1].text = RSS_CHANNEL_LINK |
74 | 78 | channel[2].text = RSS_CHANNEL_DESCRIPTION |
@@ -109,5 +113,5 @@ def rss_item(title: str | None = None, |
109 | 113 | with open(RSS_PATH, 'w') as emails_rss_file: |
110 | 114 | emails_rss_file.write(rss) |
111 | 115 |
|
112 | | -# verify RSS (XML) is parse-able |
| 116 | +# Verify RSS (XML) is parse-able |
113 | 117 | ET.ElementTree().parse(RSS_PATH) |
0 commit comments