forked from indymedia/epicyon
Date parser returns string
parent
61beedd86e
commit
fb29da5f7a
34
newswire.py
34
newswire.py
|
@ -136,8 +136,8 @@ def addNewswireDictEntry(baseDir: str, domain: str,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def parseFeedDate(pubDate: str):
|
def parseFeedDate(pubDate: str) -> str:
|
||||||
"""Returns a date object based on the given date string
|
"""Returns a UTC date string based on the given date string
|
||||||
This tries a number of formats to see which work
|
This tries a number of formats to see which work
|
||||||
"""
|
"""
|
||||||
formats = ("%a, %d %b %Y %H:%M:%S %z",
|
formats = ("%a, %d %b %Y %H:%M:%S %z",
|
||||||
|
@ -186,7 +186,14 @@ def parseFeedDate(pubDate: str):
|
||||||
hoursAdded = timedelta(hours=5)
|
hoursAdded = timedelta(hours=5)
|
||||||
publishedDate = publishedDate + hoursAdded
|
publishedDate = publishedDate + hoursAdded
|
||||||
break
|
break
|
||||||
return publishedDate
|
|
||||||
|
pubDateStr = None
|
||||||
|
if publishedDate:
|
||||||
|
pubDateStr = str(publishedDate)
|
||||||
|
if not pubDateStr.endswith('+00:00'):
|
||||||
|
pubDateStr += '+00:00'
|
||||||
|
|
||||||
|
return pubDateStr
|
||||||
|
|
||||||
|
|
||||||
def xml2StrToDict(baseDir: str, domain: str, xmlStr: str,
|
def xml2StrToDict(baseDir: str, domain: str, xmlStr: str,
|
||||||
|
@ -241,11 +248,8 @@ def xml2StrToDict(baseDir: str, domain: str, xmlStr: str,
|
||||||
pubDate = rssItem.split('<pubDate>')[1]
|
pubDate = rssItem.split('<pubDate>')[1]
|
||||||
pubDate = pubDate.split('</pubDate>')[0]
|
pubDate = pubDate.split('</pubDate>')[0]
|
||||||
|
|
||||||
publishedDate = parseFeedDate(pubDate)
|
pubDateStr = parseFeedDate(pubDate)
|
||||||
if publishedDate:
|
if pubDateStr:
|
||||||
pubDateStr = str(publishedDate)
|
|
||||||
if not pubDateStr.endswith('+00:00'):
|
|
||||||
pubDateStr += '+00:00'
|
|
||||||
postFilename = ''
|
postFilename = ''
|
||||||
votesStatus = []
|
votesStatus = []
|
||||||
addNewswireDictEntry(baseDir, domain,
|
addNewswireDictEntry(baseDir, domain,
|
||||||
|
@ -311,11 +315,8 @@ def atomFeedToDict(baseDir: str, domain: str, xmlStr: str,
|
||||||
pubDate = atomItem.split('<updated>')[1]
|
pubDate = atomItem.split('<updated>')[1]
|
||||||
pubDate = pubDate.split('</updated>')[0]
|
pubDate = pubDate.split('</updated>')[0]
|
||||||
|
|
||||||
publishedDate = parseFeedDate(pubDate)
|
pubDateStr = parseFeedDate(pubDate)
|
||||||
if publishedDate:
|
if pubDateStr:
|
||||||
pubDateStr = str(publishedDate)
|
|
||||||
if not pubDateStr.endswith('+00:00'):
|
|
||||||
pubDateStr += '+00:00'
|
|
||||||
postFilename = ''
|
postFilename = ''
|
||||||
votesStatus = []
|
votesStatus = []
|
||||||
addNewswireDictEntry(baseDir, domain,
|
addNewswireDictEntry(baseDir, domain,
|
||||||
|
@ -378,11 +379,8 @@ def atomFeedYTToDict(baseDir: str, domain: str, xmlStr: str,
|
||||||
pubDate = atomItem.split('<updated>')[1]
|
pubDate = atomItem.split('<updated>')[1]
|
||||||
pubDate = pubDate.split('</updated>')[0]
|
pubDate = pubDate.split('</updated>')[0]
|
||||||
|
|
||||||
publishedDate = parseFeedDate(pubDate)
|
pubDateStr = parseFeedDate(pubDate)
|
||||||
if publishedDate:
|
if pubDateStr:
|
||||||
pubDateStr = str(publishedDate)
|
|
||||||
if not pubDateStr.endswith('+00:00'):
|
|
||||||
pubDateStr += '+00:00'
|
|
||||||
postFilename = ''
|
postFilename = ''
|
||||||
votesStatus = []
|
votesStatus = []
|
||||||
addNewswireDictEntry(baseDir, domain,
|
addNewswireDictEntry(baseDir, domain,
|
||||||
|
|
6
tests.py
6
tests.py
|
@ -2391,7 +2391,11 @@ def testParseFeedDate():
|
||||||
pubDate = "2020-08-27T16:12:34+00:00"
|
pubDate = "2020-08-27T16:12:34+00:00"
|
||||||
publishedDate = parseFeedDate(pubDate)
|
publishedDate = parseFeedDate(pubDate)
|
||||||
assert publishedDate
|
assert publishedDate
|
||||||
print(str(publishedDate))
|
|
||||||
|
pubDate = "Sun, 22 Nov 2020 19:51:33 +0100"
|
||||||
|
publishedDate = parseFeedDate(pubDate)
|
||||||
|
# print(str(publishedDate))
|
||||||
|
assert publishedDate
|
||||||
|
|
||||||
|
|
||||||
def runAllTests():
|
def runAllTests():
|
||||||
|
|
Loading…
Reference in New Issue