adding try catch around release date parsing, getting back 000 on a null album

This commit is contained in:
andy 2022-04-10 22:18:40 +01:00
parent 54ae9aed43
commit 40d4d8ae2a

View File

@ -53,6 +53,7 @@ class SimplifiedAlbum:
self.images = [init_with_key_filter(spotframework.model.service.Image, i) for i in self.images] self.images = [init_with_key_filter(spotframework.model.service.Image, i) for i in self.images]
if isinstance(self.release_date, str): if isinstance(self.release_date, str):
try:
if self.release_date_precision == 'year': if self.release_date_precision == 'year':
self.release_date = datetime.strptime(self.release_date, '%Y') self.release_date = datetime.strptime(self.release_date, '%Y')
elif self.release_date_precision == 'month': elif self.release_date_precision == 'month':
@ -61,6 +62,9 @@ class SimplifiedAlbum:
self.release_date = datetime.strptime(self.release_date, '%Y-%m-%d') self.release_date = datetime.strptime(self.release_date, '%Y-%m-%d')
else: else:
logger.error(f'invalid release date type {self.release_date_precision} - {self.release_date}') logger.error(f'invalid release date type {self.release_date_precision} - {self.release_date}')
except ValueError:
self.release_date = datetime(year=1900, month=1, day=1)
logger.error(f'failed to parse release date for album {self.uri} {self.name} {self.artists_names} {self.release_date_precision} - {self.release_date}')
elif self.release_date is None and self.release_date_precision is None: # for podcasts elif self.release_date is None and self.release_date_precision is None: # for podcasts
self.release_date = datetime(year=1900, month=1, day=1) self.release_date = datetime(year=1900, month=1, day=1)