def move_events(): db = DbStore() total = util.get_spotify_db().events.find().count() for i, event in enumerate(util.get_spotify_db().events.find()): if i % 100 == 0: print("Moving events {}%".format(util.percent(i, total))) db.add_event(event) db.commit()
def fix_tracks(creds: Credentials, db: DbStore): track_ids = db.track_ids() full_tracks = get_tracks(track_ids, creds, UPDATE_SLEEP_MS) logging.info("Downloaded all tracks, updating db...") for track in full_tracks: for artist in track["artists"]: db.add_track_artist(track["id"], artist["id"]) for artist in track["album"]["artists"]: db.add_album_artist(track["album"]["id"], artist["id"]) db.commit() logging.info("Fixed all tracks")
def add_prev_track_id(db: DbStore): events = db.events_with_track_id() prev_track_id = events[0]["state"]["track_id"] n_updated = 0 for event in events[1:]: track_id = event["state"]["track_id"] if track_id != prev_track_id and event.get("prev_track_id") != prev_track_id: n_updated += 1 db.set_prev_track_id(event["state"]["timestamp"], prev_track_id) prev_track_id = track_id db.commit() logging.info("Added prev track info to {} items".format(n_updated))