updated last.fm actions to catch fmframework exceptions
This commit is contained in:
parent
c2b537e39f
commit
d6c66efdab
@ -11,6 +11,8 @@ from spotfm.maths.counter import Counter
|
|||||||
from spotframework.model.uri import Uri
|
from spotframework.model.uri import Uri
|
||||||
from spotframework.net.network import SpotifyNetworkException
|
from spotframework.net.network import SpotifyNetworkException
|
||||||
|
|
||||||
|
from fmframework.net.network import LastFMNetworkException
|
||||||
|
|
||||||
db = firestore.Client()
|
db = firestore.Client()
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -45,11 +47,15 @@ def refresh_lastfm_track_stats(username, playlist_name):
|
|||||||
return
|
return
|
||||||
track_count = counter.count_playlist(playlist=spotify_playlist)
|
track_count = counter.count_playlist(playlist=spotify_playlist)
|
||||||
|
|
||||||
|
try:
|
||||||
user_count = fmnet.get_user_scrobble_count()
|
user_count = fmnet.get_user_scrobble_count()
|
||||||
if user_count > 0:
|
if user_count > 0:
|
||||||
percent = round((track_count * 100) / user_count, 2)
|
percent = round((track_count * 100) / user_count, 2)
|
||||||
else:
|
else:
|
||||||
percent = 0
|
percent = 0
|
||||||
|
except LastFMNetworkException as e:
|
||||||
|
logger.error(f'error while retrieving user scrobble count - {e}')
|
||||||
|
percent = 0
|
||||||
|
|
||||||
playlist.lastfm_stat_count = track_count
|
playlist.lastfm_stat_count = track_count
|
||||||
playlist.lastfm_stat_percent = percent
|
playlist.lastfm_stat_percent = percent
|
||||||
@ -87,11 +93,15 @@ def refresh_lastfm_album_stats(username, playlist_name):
|
|||||||
return
|
return
|
||||||
album_count = counter.count_playlist(playlist=spotify_playlist, query_album=True)
|
album_count = counter.count_playlist(playlist=spotify_playlist, query_album=True)
|
||||||
|
|
||||||
|
try:
|
||||||
user_count = fmnet.get_user_scrobble_count()
|
user_count = fmnet.get_user_scrobble_count()
|
||||||
if user_count > 0:
|
if user_count > 0:
|
||||||
album_percent = round((album_count * 100) / user_count, 2)
|
album_percent = round((album_count * 100) / user_count, 2)
|
||||||
else:
|
else:
|
||||||
album_percent = 0
|
album_percent = 0
|
||||||
|
except LastFMNetworkException as e:
|
||||||
|
logger.error(f'error while retrieving user scrobble count - {e}')
|
||||||
|
album_percent = 0
|
||||||
|
|
||||||
playlist.lastfm_stat_album_count = album_count
|
playlist.lastfm_stat_album_count = album_count
|
||||||
playlist.lastfm_stat_album_percent = album_percent
|
playlist.lastfm_stat_album_percent = album_percent
|
||||||
@ -129,11 +139,15 @@ def refresh_lastfm_artist_stats(username, playlist_name):
|
|||||||
return
|
return
|
||||||
artist_count = counter.count_playlist(playlist=spotify_playlist, query_artist=True)
|
artist_count = counter.count_playlist(playlist=spotify_playlist, query_artist=True)
|
||||||
|
|
||||||
|
try:
|
||||||
user_count = fmnet.get_user_scrobble_count()
|
user_count = fmnet.get_user_scrobble_count()
|
||||||
if user_count > 0:
|
if user_count > 0:
|
||||||
artist_percent = round((artist_count * 100) / user_count, 2)
|
artist_percent = round((artist_count * 100) / user_count, 2)
|
||||||
else:
|
else:
|
||||||
artist_percent = 0
|
artist_percent = 0
|
||||||
|
except LastFMNetworkException as e:
|
||||||
|
logger.error(f'error while retrieving user scrobble count - {e}')
|
||||||
|
artist_percent = 0
|
||||||
|
|
||||||
playlist.lastfm_stat_artist_count = artist_count
|
playlist.lastfm_stat_artist_count = artist_count
|
||||||
playlist.lastfm_stat_artist_percent = artist_percent
|
playlist.lastfm_stat_artist_percent = artist_percent
|
||||||
|
@ -5,6 +5,8 @@ import music.db.database as database
|
|||||||
from music.model.user import User
|
from music.model.user import User
|
||||||
from music.model.tag import Tag
|
from music.model.tag import Tag
|
||||||
|
|
||||||
|
from fmframework.net.network import LastFMNetworkException
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -33,20 +35,28 @@ def update_tag(username, tag_id):
|
|||||||
return
|
return
|
||||||
|
|
||||||
tag_count = 0
|
tag_count = 0
|
||||||
|
try:
|
||||||
user_scrobbles = net.get_user_scrobble_count()
|
user_scrobbles = net.get_user_scrobble_count()
|
||||||
|
except LastFMNetworkException as e:
|
||||||
|
logger.error(f'error retrieving scrobble count - {e}')
|
||||||
|
user_scrobbles = 0
|
||||||
|
|
||||||
artists = []
|
artists = []
|
||||||
for artist in tag.artists:
|
for artist in tag.artists:
|
||||||
|
try:
|
||||||
net_artist = net.get_artist(name=artist['name'])
|
net_artist = net.get_artist(name=artist['name'])
|
||||||
|
|
||||||
if net_artist is not None:
|
if net_artist is not None:
|
||||||
artist['count'] = net_artist.user_scrobbles
|
artist['count'] = net_artist.user_scrobbles
|
||||||
tag_count += net_artist.user_scrobbles
|
tag_count += net_artist.user_scrobbles
|
||||||
|
except LastFMNetworkException as e:
|
||||||
|
logger.error(f'error during artist retrieval - {e}')
|
||||||
|
|
||||||
artists.append(artist)
|
artists.append(artist)
|
||||||
|
|
||||||
albums = []
|
albums = []
|
||||||
for album in tag.albums:
|
for album in tag.albums:
|
||||||
|
try:
|
||||||
net_album = net.get_album(name=album['name'], artist=album['artist'])
|
net_album = net.get_album(name=album['name'], artist=album['artist'])
|
||||||
|
|
||||||
if net_album is not None:
|
if net_album is not None:
|
||||||
@ -54,11 +64,14 @@ def update_tag(username, tag_id):
|
|||||||
|
|
||||||
if album['artist'].lower() not in [i.lower() for i in [j['name'] for j in artists]]:
|
if album['artist'].lower() not in [i.lower() for i in [j['name'] for j in artists]]:
|
||||||
tag_count += net_album.user_scrobbles
|
tag_count += net_album.user_scrobbles
|
||||||
|
except LastFMNetworkException as e:
|
||||||
|
logger.error(f'error during album retrieval - {e}')
|
||||||
|
|
||||||
albums.append(album)
|
albums.append(album)
|
||||||
|
|
||||||
tracks = []
|
tracks = []
|
||||||
for track in tag.tracks:
|
for track in tag.tracks:
|
||||||
|
try:
|
||||||
net_track = net.get_track(name=track['name'], artist=track['artist'])
|
net_track = net.get_track(name=track['name'], artist=track['artist'])
|
||||||
|
|
||||||
if net_track is not None:
|
if net_track is not None:
|
||||||
@ -66,6 +79,8 @@ def update_tag(username, tag_id):
|
|||||||
|
|
||||||
if track['artist'].lower() not in [i.lower() for i in [j['name'] for j in artists]]:
|
if track['artist'].lower() not in [i.lower() for i in [j['name'] for j in artists]]:
|
||||||
tag_count += net_track.user_scrobbles
|
tag_count += net_track.user_scrobbles
|
||||||
|
except LastFMNetworkException as e:
|
||||||
|
logger.error(f'error during track retrieval - {e}')
|
||||||
|
|
||||||
tracks.append(track)
|
tracks.append(track)
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
astroid==2.4.2
|
astroid==2.4.2
|
||||||
cachetools==4.1.0
|
cachetools==4.1.0
|
||||||
certifi==2020.4.5.2
|
certifi==2020.6.20
|
||||||
chardet==3.0.4
|
chardet==3.0.4
|
||||||
click==7.1.2
|
click==7.1.2
|
||||||
fireo==1.3.3
|
fireo==1.3.3
|
||||||
Flask==1.1.2
|
Flask==1.1.2
|
||||||
google-api-core==1.20.1
|
google-api-core==1.21.0
|
||||||
google-auth==1.17.2
|
google-auth==1.18.0
|
||||||
google-cloud-core==1.3.0
|
google-cloud-core==1.3.0
|
||||||
google-cloud-firestore==1.7.0
|
google-cloud-firestore==1.7.0
|
||||||
google-cloud-logging==1.15.0
|
google-cloud-logging==1.15.0
|
||||||
@ -14,7 +14,7 @@ google-cloud-pubsub==1.6.0
|
|||||||
google-cloud-tasks==1.5.0
|
google-cloud-tasks==1.5.0
|
||||||
googleapis-common-protos==1.52.0
|
googleapis-common-protos==1.52.0
|
||||||
grpc-google-iam-v1==0.12.3
|
grpc-google-iam-v1==0.12.3
|
||||||
grpcio==1.29.0
|
grpcio==1.30.0
|
||||||
idna==2.9
|
idna==2.9
|
||||||
isort==4.3.21
|
isort==4.3.21
|
||||||
itsdangerous==1.1.0
|
itsdangerous==1.1.0
|
||||||
@ -22,14 +22,14 @@ Jinja2==2.11.2
|
|||||||
lazy-object-proxy==1.5.0
|
lazy-object-proxy==1.5.0
|
||||||
MarkupSafe==1.1.1
|
MarkupSafe==1.1.1
|
||||||
mccabe==0.6.1
|
mccabe==0.6.1
|
||||||
numpy==1.18.5
|
numpy==1.19.0
|
||||||
opencv-python==4.2.0.34
|
opencv-python==4.2.0.34
|
||||||
protobuf==3.12.2
|
protobuf==3.12.2
|
||||||
pyasn1==0.4.8
|
pyasn1==0.4.8
|
||||||
pyasn1-modules==0.2.8
|
pyasn1-modules==0.2.8
|
||||||
pylint==2.5.3
|
pylint==2.5.3
|
||||||
pytz==2020.1
|
pytz==2020.1
|
||||||
requests==2.23.0
|
requests==2.24.0
|
||||||
rsa==4.6
|
rsa==4.6
|
||||||
six==1.15.0
|
six==1.15.0
|
||||||
tabulate==0.8.7
|
tabulate==0.8.7
|
||||||
|
Loading…
Reference in New Issue
Block a user