diff options
Diffstat (limited to 'scripts/populate')
-rw-r--r-- | scripts/populate/api.py | 5 | ||||
-rw-r--r-- | scripts/populate/database.py | 18 | ||||
-rw-r--r-- | scripts/populate/parser.py | 17 | ||||
-rw-r--r-- | scripts/populate/structures.py | 2 |
4 files changed, 27 insertions, 15 deletions
diff --git a/scripts/populate/api.py b/scripts/populate/api.py index 5cc24d3..9133c25 100644 --- a/scripts/populate/api.py +++ b/scripts/populate/api.py @@ -14,8 +14,9 @@ def download_albums(albums): def get_album_json(artist_name, album_name): - if os.path.isfile(parser.getLink(album_name)): + link = parser.get_link(album_name) + if os.path.isfile(link): return album = genius.search_album(album_name, artist_name) - album.save_lyrics() + album.save_lyrics(f"{link}") diff --git a/scripts/populate/database.py b/scripts/populate/database.py index 2319812..eaccfd2 100644 --- a/scripts/populate/database.py +++ b/scripts/populate/database.py @@ -16,19 +16,17 @@ connector = mysql.connector.connect( cursor = connector.cursor() - - def process_albums(album_list): [process_album(album, album_id) for album_id, album in enumerate(album_list, 1)] def process_album(album, album_id): - upload_album(album) + upload_album(album, album_id) [upload_song(song, album_id) for song in album.songs] -def upload_album(album): +def upload_album(album, album_id): album.name = album.name.lower() cursor.execute(""" INSERT INTO album ( @@ -40,9 +38,19 @@ def upload_album(album): """, { 'name': album.name, 'cover': album.cover, - 'artist_id': album.artist + 'artist_id': album.artist, }) + if album.release: + cursor.execute(""" + UPDATE album + SET release_date = (%(release)s) + WHERE id = %(album_id)s; + """, { + 'release': album.release, + 'album_id': album_id, + }) + def upload_song(song, album_id): cursor.execute(""" diff --git a/scripts/populate/parser.py b/scripts/populate/parser.py index cbb51b5..fdce1c9 100644 --- a/scripts/populate/parser.py +++ b/scripts/populate/parser.py @@ -5,7 +5,7 @@ import os def process_json_file(name, album_id, artist_id): - link = getLink(name) + link = get_link(name) file_json = open(link, "r") album_json = file_json.read() @@ -14,8 +14,8 @@ def process_json_file(name, album_id, artist_id): return process_json(album_json, album_id, artist_id) -def getLink(name): - return "Lyrics_"+name.replace(" ", "")+".json" +def get_link(name): + return name.replace(" ", "")+".json" def process_json(album_json, album_id, artist_id): @@ -27,10 +27,13 @@ def process_json(album_json, album_id, artist_id): new_cover = get_cover_link(artist_id, album_id) download_cover(off_cover, new_cover, artist_id) - year = data["release_date_components"]["year"] - month = data["release_date_components"]["year"] - day = data["release_date_components"]["year"] - release = [year, month, day] + if data["release_date_components"]: + year = data["release_date_components"]["year"] + month = data["release_date_components"]["month"] + day = data["release_date_components"]["day"] + release = f"{year}-{month}-{day}" + else: + release = None songs = [analyze_song(song) for song in data["tracks"]] return structures.album(album_name, new_cover, songs, artist_id, release) diff --git a/scripts/populate/structures.py b/scripts/populate/structures.py index 31feb1b..b6cd8cd 100644 --- a/scripts/populate/structures.py +++ b/scripts/populate/structures.py @@ -5,7 +5,7 @@ class song: class album: - def __init__(self, name, cover, songs, artist_id, release=None): + def __init__(self, name, cover, songs, artist_id, release = None): self.name = name self.cover = cover self.songs = songs |