File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 11#!/bin/python3
22
3+ import calendar
34from datetime import datetime
45import json
56import xml .etree .ElementTree as ET
@@ -41,7 +42,15 @@ def rss_item(title: str | None = None,
4142 # https://validator.w3.org/feed/docs/error/InvalidRFC2822Date.html
4243 if pubDate is not None :
4344 item .append (ET .Element ("pubDate" ))
44- fmt_date = datetime .strptime (pubDate , "%B %d, %Y" ).strftime ("%d %b %Y" )
45+
46+ # Make sure months are processed correctly when there's some inconsistency
47+ # https://docs.python.org/3/library/datetime.html#format-codes
48+ if pubDate in calendar .month_name :
49+ fmt_date = datetime .strptime (pubDate , "%B %d, %Y" ).strftime ("%d %b %Y" )
50+ elif pubDate in calendar .month_abbr :
51+ fmt_date = datetime .strptime (pubDate , "%b %d, %Y" ).strftime ("%d %b %Y" )
52+ else :
53+ fmt_date = '01 January 1970' # Just default to UNIX start
4554 item [- 1 ].text = fmt_date
4655
4756 return item
You can’t perform that action at this time.
0 commit comments