From 03cfcc05700a61be7cdf0f37b09cf8a75551dbe3 Mon Sep 17 00:00:00 2001 From: simon987 Date: Sun, 14 Jun 2020 14:08:08 -0400 Subject: [PATCH] fixes --- bootstrap.sh | 6 +++++- task_get_lastfm.py | 4 ++-- task_get_spotify.py | 14 +++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index f969d91..533e861 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +tmux kill-session -t mgSpotify +tmux kill-session -t mgCover +tmux kill-session -t mgLastfm + tmux new -d -s mgCover bash -c "./task_runner.sh task_get_cover.py --count 100 --threads 2" -tmux new -d -s mgLastfm bash -c "./task_runner.sh task_get_lastfm.py --count 500 --threads 5" +tmux new -d -s mgLastfm bash -c "./task_runner.sh task_get_lastfm.py --count 200 --threads 4" tmux new -d -s mgSpotify bash -c "./task_runner.sh task_get_spotify.py --count 500 --threads 10" diff --git a/task_get_lastfm.py b/task_get_lastfm.py index f5dffc7..2fc74e6 100755 --- a/task_get_lastfm.py +++ b/task_get_lastfm.py @@ -34,7 +34,7 @@ def save_tags(conn, lfm_name, tags): cur.execute("DELETE FROM mg.lastfm_artist_tag WHERE name=%s", (lfm_name,)) cur.execute( "INSERT INTO mg.lastfm_artist_tag VALUES %s" % - ",".join("('%s', '%s')" % (n, t.strip().replace("'", "''")) for (n, t) in zip(repeat(lfm_name), tags)) + ",".join("('%s', '%s')" % (n.replace("'", "''"), t.strip().replace("'", "''")) for (n, t) in zip(repeat(lfm_name), tags)) ) @@ -46,7 +46,7 @@ def save_data(conn, data): disambiguate(conn, similar["name"], similar["mbid"]) save_similar(conn, data["name"], similar["name"], similar["match"]) - save_tags(conn, data["name"], data["tags"]) + save_tags(conn, data["name"], set(data["tags"])) save_meta(conn, data["name"], data["listeners"], data["playcount"]) diff --git a/task_get_spotify.py b/task_get_spotify.py index b343542..7384e1b 100755 --- a/task_get_spotify.py +++ b/task_get_spotify.py @@ -51,7 +51,8 @@ def save_artist(conn, data, max_age_days=30): def get_albums(conn, spotify, spotid): - data = silent_stdout(spotify.artist_albums, spotid, album_type="album,single,compilation") + with silent_stdout: + data = spotify.artist_albums(spotid, album_type="album,single,compilation") save_raw(conn, spotid, "artist_albums", data) cur = conn.cursor() @@ -66,7 +67,8 @@ def get_albums(conn, spotify, spotid): def get_tracks(conn, spotify, spotid): - data = silent_stdout(spotify.artist_top_tracks, spotid) + with silent_stdout: + data = spotify.artist_top_tracks(spotid) save_raw(conn, spotid, "artist_top_tracks", data) cur = conn.cursor() @@ -89,7 +91,8 @@ def get_tracks(conn, spotify, spotid): def related(conn, spotify, spotid): - data = silent_stdout(spotify.artist_related_artists, spotid) + with silent_stdout: + data = spotify.artist_related_artists(spotid) save_raw(conn, spotid, "artist_related_artists", data) return data["artists"] @@ -210,7 +213,8 @@ def save_spotid_to_mbid(conn, spotid, mbid): def search_artist(conn, spotify, name): quoted_name = "\"%s\"" % name - data = silent_stdout(spotify.search, quoted_name, type="artist", limit=20) + with silent_stdout: + data = spotify.search(quoted_name, type="artist", limit=20) save_raw(conn, name, "search", data) for result in data["artists"]["items"]: @@ -271,7 +275,7 @@ if __name__ == "__main__": queue = Queue() conn = psycopg2.connect(config.connstr()) - for task in get_tasks(conn, args.count): + for task in get_tasks(conn, args.count): queue.put(task) conn.close()