fixing a divide by 0, dict instead of list

This commit is contained in:
Andy Pack 2022-11-09 08:56:23 +00:00
parent 25df6a3028
commit 3a1045d6ce
Signed by: sarsoo
GPG Key ID: A55BA3536A5E0ED7
2 changed files with 18 additions and 11 deletions

View File

@ -78,9 +78,9 @@ def run_user_playlist(user: User, playlist: Playlist, spotnet: SpotNetwork = Non
try:
if not playlist.include_spotify_owned:
user_playlists = [(i.name, i.uri) for i in spotnet.playlists() if 'spotify' not in i.owner.display_name.lower()]
user_playlists = {i.name: i.uri for i in spotnet.playlists() if 'spotify' not in i.owner.display_name.lower()}
else:
user_playlists = [(i.name, i.uri) for i in spotnet.playlists()]
user_playlists = {i.name: i.uri for i in spotnet.playlists()}
except SpotifyNetworkException as e:
logger.exception(f'error occured while retrieving playlists {username} / {playlist_name}')
raise e
@ -102,7 +102,7 @@ def run_user_playlist(user: User, playlist: Playlist, spotnet: SpotNetwork = Non
log_name = uri
except ValueError: # is a playlist name
part_playlist = next((i for i in user_playlists if i[0] == part_name), None)
part_playlist = user_playlists.get(part_name)
if part_playlist is None:
logger.warning(f'playlist {part_name} not found {username} / {playlist_name}')
continue

View File

@ -61,12 +61,6 @@ def update_tag(user, tag, spotnet=None, fmnet=None):
tag.count = 0
tag.total_time_ms = 0
try:
user_scrobbles = fmnet.user_scrobble_count()
except LastFMNetworkException:
logger.exception(f'error retrieving scrobble count {username} / {tag_id}')
user_scrobbles = 1
artists = []
for artist in tag.artists:
try:
@ -160,8 +154,21 @@ def update_tag(user, tag, spotnet=None, fmnet=None):
tag.artists = artists
tag.total_time = seconds_to_time_str(milliseconds=tag.total_time_ms)
try:
user_scrobbles = fmnet.user_scrobble_count()
except LastFMNetworkException:
logger.exception(f'error retrieving scrobble count {username} / {tag_id}')
user_scrobbles = 0
if user_scrobbles > 0:
tag.total_user_scrobbles = user_scrobbles
tag.proportion = (tag.count / user_scrobbles) * 100
else:
logger.warning(f'user scrobble count for {username} returned 0')
tag.total_user_scrobbles = 0
tag.proportion = 0
tag.last_updated = datetime.utcnow()
tag.update()