1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

[pixiv] work around strptime limitations in Python < 3.7

"%z" doesn't allow a colon separator in older Python versions:
    - "+0900" is OK
    - "+09:00" raises an exception
This commit is contained in:
Mike Fährmann 2019-05-08 18:00:40 +02:00
parent 1f7fa9dc8e
commit 4736912d4e
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 4 additions and 4 deletions

View File

@ -42,7 +42,7 @@ class PixivExtractor(Extractor):
del work["meta_pages"] del work["meta_pages"]
work["num"] = "" work["num"] = ""
work["tags"] = [tag["name"] for tag in work["tags"]] work["tags"] = [tag["name"] for tag in work["tags"]]
work["date"] = text.parse_datetime(work["create_date"]) work["date"] = text.parse_datetime(work["create_date"][:-3] + "00")
work.update(metadata) work.update(metadata)
yield Message.Directory, work yield Message.Directory, work

View File

@ -353,11 +353,11 @@ class TestText(unittest.TestCase):
def test_parse_datetime(self, f=text.parse_datetime): def test_parse_datetime(self, f=text.parse_datetime):
null = datetime.datetime.utcfromtimestamp(0) null = datetime.datetime.utcfromtimestamp(0)
self.assertEqual(f("1970-01-01T00:00:00+00:00"), null) self.assertEqual(f("1970-01-01T00:00:00+0000"), null)
self.assertEqual(f("1970.01.01", "%Y.%m.%d") , null) self.assertEqual(f("1970.01.01", "%Y.%m.%d") , null)
self.assertEqual( self.assertEqual(
f("2019-05-07T21:25:02+09:00"), f("2019-05-07T21:25:02+0900"),
datetime.datetime(2019, 5, 7, 12, 25, 2), datetime.datetime(2019, 5, 7, 12, 25, 2),
) )