Handle different rss date formats

merge-requests/8/head
Bob Mottram 2020-10-03 22:59:38 +01:00
parent e6b66d5cb5
commit e0162738d4
1 changed files with 11 additions and 0 deletions

View File

@ -119,12 +119,23 @@ def xml2StrToDict(xmlStr: str) -> {}:
link = link.split('</link>')[0]
pubDate = rssItem.split('<pubDate>')[1]
pubDate = pubDate.split('</pubDate>')[0]
parsed = False
try:
publishedDate = \
datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S %z")
result[str(publishedDate)] = [title, link]
parsed = True
except BaseException:
pass
if not parsed:
try:
publishedDate = \
datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S UT")
result[str(publishedDate)] = [title, link]
parsed = True
except BaseException:
print('WARN: unrecognized RSS date format: ' + pubDate)
pass
return result