From 1ddabab55f38fb7e1bbd6729b980c290c9fdc0fa Mon Sep 17 00:00:00 2001 From: Albert Suarez Date: Fri, 9 Aug 2019 12:58:28 +0200 Subject: [PATCH] Removed the local version of the file and added some comments --- src/__main__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/__main__.py b/src/__main__.py index 1310e52..9e8e2cc 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -1,3 +1,5 @@ +import os + from tqdm import tqdm from src import * @@ -6,11 +8,13 @@ def scrape(): for artist_letter in tqdm(AZ_LYRICS_ARTIST_LETTER_LIST, total=len(AZ_LYRICS_ARTIST_LETTER_LIST)): + # Downloads file if it is available on Box folder. csv_file_name = f'{CSV_FILE}_{artist_letter}.csv' file_id = box_sdk.search_file(BOX_FOLDER_APP_ID, csv_file_name.split('/')[-1]) if file_id: box_sdk.download_file(file_id, csv_file_name) + # Iterates over all artists with the given letter. artist_url_list = azlyrics.get_artist_url_list(artist_letter) for artist_name, artist_url in tqdm(artist_url_list, total=len(artist_url_list)): song_url_list = azlyrics.get_song_url_list(artist_url) @@ -18,11 +22,15 @@ def scrape(): if not csv_parser.exists_song(artist_letter, artist_url, song_url): song_lyrics = azlyrics.get_song_lyrics(song_url) csv_parser.append_to_csv(artist_name, artist_url, song_name, song_url, song_lyrics, artist_letter) + # Uploads or updates the CSV on Box per every artist. if file_id: file_id = box_sdk.update_file(file_id, csv_file_name) else: file_id = box_sdk.upload_file(BOX_FOLDER_APP_ID, csv_file_name) + # Removes the local version of the CSV for saving storage. + os.remove(csv_file_name) + if __name__ == '__main__': scrape()