removing punctuation from spotify search
This commit is contained in:
parent
faeda66041
commit
90cdccbbc6
@ -59,7 +59,7 @@ def populated_features(spotnet: SpotNetwork,
|
||||
except (KeyError, TypeError):
|
||||
for_pulling.append(row)
|
||||
|
||||
# GET SPOTIFY TRACKS
|
||||
# GET SPOTIFY TRACKS FOR CACHE FAILURES
|
||||
logger.info('pulling tracks')
|
||||
tracks = spotnet.tracks(uris=[i.uri for i in for_pulling])
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import datetime
|
||||
import logging
|
||||
import string
|
||||
from csv import DictWriter
|
||||
|
||||
from analysis.cache import Cache
|
||||
@ -33,26 +34,34 @@ def populated_scrobbles(spotnet: SpotNetwork,
|
||||
# get all scrobbles for date range
|
||||
scrobbles = fmnet.recent_tracks(limit=limit, from_time=from_date, to_time=to_date, page_limit=200)
|
||||
|
||||
punc_stripper = str.maketrans('', '', string.punctuation)
|
||||
|
||||
# populate with uris
|
||||
for scrobble in scrobbles:
|
||||
|
||||
cache_entry = cache.get_track(name=scrobble.track.name.lower(), artist=scrobble.track.artist.name.lower())
|
||||
|
||||
if cache_entry is not None and cache_entry.get('uri'):
|
||||
try:
|
||||
# uri is cached
|
||||
scrobble.uri = cache_entry.get('uri')
|
||||
else:
|
||||
scrobble.uri = cache_entry['uri']
|
||||
except (TypeError, KeyError):
|
||||
# TypeError for cache_entry == None, KeyError for uri key existing
|
||||
# cache missed or doesn't have uri
|
||||
logger.info(f'pulling {scrobble.track}')
|
||||
spotify_search = spotnet.search(query_types=[Uri.ObjectType.track],
|
||||
track=scrobble.track.name,
|
||||
artist=scrobble.track.artist.name,
|
||||
track=scrobble.track.name.translate(punc_stripper),
|
||||
artist=scrobble.track.artist.name.translate(punc_stripper),
|
||||
response_limit=5).tracks
|
||||
if len(spotify_search) > 0:
|
||||
top_result = spotify_search[0]
|
||||
|
||||
if top_result.name.lower() != scrobble.track.name.lower() or top_result.artists[0].name.lower() != scrobble.track.artist.name.lower():
|
||||
logger.info(f'{scrobble.track.name} - {scrobble.track.artist.name} != {top_result.name} - {top_result.artists[0].name}')
|
||||
|
||||
cache.set_track(name=scrobble.track.name.lower(),
|
||||
artist=scrobble.track.artist.name.lower(),
|
||||
uri=str(spotify_search[0].uri))
|
||||
scrobble.uri = str(spotify_search[0].uri)
|
||||
uri=str(top_result.uri))
|
||||
scrobble.uri = str(top_result.uri)
|
||||
else:
|
||||
logger.debug('no search tracks returned')
|
||||
scrobble.uri = None
|
||||
|
4239
playlist-nn.ipynb
4239
playlist-nn.ipynb
File diff suppressed because one or more lines are too long
123
stats.ipynb
123
stats.ipynb
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user