Use isodate instead of strptime to parse published date.

This commit is contained in:
voussoir 2020-08-11 23:20:26 -07:00
parent dfa5bb2390
commit 323b2ead54

View file

@ -1,7 +1,6 @@
import apiclient.discovery import apiclient.discovery
import datetime
import logging
import isodate import isodate
import logging
from . import helpers from . import helpers
@ -37,10 +36,7 @@ class Video:
self.author_name = snippet.get('channelTitle', self.author_id) self.author_name = snippet.get('channelTitle', self.author_id)
# Something like '2016-10-01T21:00:01' # Something like '2016-10-01T21:00:01'
self.published_string = snippet['publishedAt'] self.published_string = snippet['publishedAt']
published = snippet['publishedAt'].split('.')[0] self.published = isodate.parse_datetime(self.published_string).timestamp()
published = published.rstrip('Z')
published = datetime.datetime.strptime(published, '%Y-%m-%dT%H:%M:%S')
self.published = published.timestamp()
self.tags = snippet.get('tags', []) self.tags = snippet.get('tags', [])
self.duration = isodate.parse_duration(content_details['duration']).seconds self.duration = isodate.parse_duration(content_details['duration']).seconds