fixing a divide by 0, dict instead of list
This commit is contained in:
parent
25df6a3028
commit
3a1045d6ce
@ -78,9 +78,9 @@ def run_user_playlist(user: User, playlist: Playlist, spotnet: SpotNetwork = Non
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if not playlist.include_spotify_owned:
|
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:
|
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:
|
except SpotifyNetworkException as e:
|
||||||
logger.exception(f'error occured while retrieving playlists {username} / {playlist_name}')
|
logger.exception(f'error occured while retrieving playlists {username} / {playlist_name}')
|
||||||
raise e
|
raise e
|
||||||
@ -102,7 +102,7 @@ def run_user_playlist(user: User, playlist: Playlist, spotnet: SpotNetwork = Non
|
|||||||
log_name = uri
|
log_name = uri
|
||||||
|
|
||||||
except ValueError: # is a playlist name
|
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:
|
if part_playlist is None:
|
||||||
logger.warning(f'playlist {part_name} not found {username} / {playlist_name}')
|
logger.warning(f'playlist {part_name} not found {username} / {playlist_name}')
|
||||||
continue
|
continue
|
||||||
|
@ -61,12 +61,6 @@ def update_tag(user, tag, spotnet=None, fmnet=None):
|
|||||||
tag.count = 0
|
tag.count = 0
|
||||||
tag.total_time_ms = 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 = []
|
artists = []
|
||||||
for artist in tag.artists:
|
for artist in tag.artists:
|
||||||
try:
|
try:
|
||||||
@ -160,8 +154,21 @@ def update_tag(user, tag, spotnet=None, fmnet=None):
|
|||||||
tag.artists = artists
|
tag.artists = artists
|
||||||
|
|
||||||
tag.total_time = seconds_to_time_str(milliseconds=tag.total_time_ms)
|
tag.total_time = seconds_to_time_str(milliseconds=tag.total_time_ms)
|
||||||
tag.total_user_scrobbles = user_scrobbles
|
|
||||||
tag.proportion = (tag.count / user_scrobbles) * 100
|
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.last_updated = datetime.utcnow()
|
||||||
|
|
||||||
tag.update()
|
tag.update()
|
||||||
|
Loading…
Reference in New Issue
Block a user