From 2e8ddbf422a3a6d75b1e1f73cad089111f801c05 Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Tue, 24 Sep 2024 12:21:40 +0200 Subject: finished web scrapper --- scrap/main.py | 53 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'scrap/main.py') diff --git a/scrap/main.py b/scrap/main.py index 80f4d24..72a9929 100644 --- a/scrap/main.py +++ b/scrap/main.py @@ -1,18 +1,49 @@ -import lyricsgenius -import sys +from albums import album_data +import api +import parser +import database -def getAlbum(artist_name, album_name): - genius = lyricsgenius.Genius( - "0uSA9UFGsiO2WozVmbWPhyhOoVmUNuM3PXRt9rvWhptHBMgSO5CZBxGUMkwet5mv" +def start(): + print("do you want to download the json data from genius? [y, n] ", end="") + if input().lower() == "y": + api.download_albums(album_data) + print("download finished!") + + database.setup() + upload_albums( + get_album_data(), + get_artist_names() ) - album = genius.search_album(artist_name, album_name) - album.save_lyrics() + database.close() + print("upload finished!") + print("remember to move the covers directory once you're done!") + + +def upload_albums(album_data, artist_names): + database.process_artists(artist_names) + database.process_albums(album_data) + + +def get_album_data(): + album_data = [] + artist_id = 0 + + for artist in album_data: + artist_id += 1 + + for album in artist[1]: + album_data.append(parser.process_json_file(album, artist_id)) + + return album_data -def getJsonLyrics(link): - for key, value in data.items(): - print(key, value) +def get_artist_names(): + artist_data = [] + [artist_data.append( + artist[0] + ) for artist in album_data] + return artist_data -getJsonLyrics(sys.argv[1]) +start() -- cgit v1.2.3