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,14 +53,18 @@ 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):
if self.release_date_precision == 'year': try:
self.release_date = datetime.strptime(self.release_date, '%Y') if self.release_date_precision == 'year':
elif self.release_date_precision == 'month': self.release_date = datetime.strptime(self.release_date, '%Y')
self.release_date = datetime.strptime(self.release_date, '%Y-%m') elif self.release_date_precision == 'month':
elif self.release_date_precision == 'day': self.release_date = datetime.strptime(self.release_date, '%Y-%m')
self.release_date = datetime.strptime(self.release_date, '%Y-%m-%d') elif self.release_date_precision == 'day':
else: self.release_date = datetime.strptime(self.release_date, '%Y-%m-%d')
logger.error(f'invalid release date type {self.release_date_precision} - {self.release_date}') else:
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)