From 456b4202b129e76684f1d4a0ec8255a8c853de80 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 20 Oct 2020 13:37:32 +0100 Subject: [PATCH] Convert dates with offset --- newsdaemon.py | 9 +++++++-- newswire.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/newsdaemon.py b/newsdaemon.py index 91229b2f..4cb54676 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -478,8 +478,13 @@ def convertRSStoActivityPub(baseDir: str, httpPrefix: str, for dateStr, item in newswireReverse.items(): originalDateStr = dateStr # convert the date to the format used by ActivityPub - dateStr = dateStr.replace(' ', 'T') - dateStr = dateStr.replace('+00:00', 'Z') + if '+00:00' in dateStr: + dateStr = dateStr.replace(' ', 'T') + dateStr = dateStr.replace('+00:00', 'Z') + else: + dateStrWithOffset = \ + datetime.datetime.strptime(dateStr, "%Y-%m-%d %H:%M:%S%z") + dateStr = dateStrWithOffset.strftime("%Y-%m-%dT%H:%M:%SZ") statusNumber, published = getStatusNumber(dateStr) newPostId = \ diff --git a/newswire.py b/newswire.py index 8edb475c..9ed0ab88 100644 --- a/newswire.py +++ b/newswire.py @@ -344,7 +344,7 @@ def getRSSfromDict(baseDir: str, newswire: {}, published = published.replace(' ', 'T') else: publishedWithOffset = \ - datetime.datetime.strptime(published, "%Y-%m-%d %H:%M:%S%z") + datetime.strptime(published, "%Y-%m-%d %H:%M:%S%z") published = publishedWithOffset.strftime("%Y-%m-%dT%H:%M:%SZ") try: pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")