diff --git a/main.py b/main.py index 3bacbff..1281a47 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,22 @@ import pull import process import logging -cache = json.load(open(os.path.join(sys.path[0], f'.cache-{auth.username}'))) -if time.time() > cache['expires_at']: - pull.main() \ No newline at end of file +def main(): + logging.basicConfig(level=logging.INFO) + logging.info('Pulling data from Spotify') + refresh() + + +# Refreshes tracks from files if the token from Spotipy has expired, +# thus keeping us up to date in most cases while keeping rate limits +def refresh(): + file_path = os.path.join(sys.path[0], f'.cache-{auth.username}') + if os.path.exists(file_path): + cache = json.load(open(file_path, 'r')) + if time.time() > cache['expires_at']: + logging.info('Refreshing Spotify data by pulling tracks, this may take a moment.') + pull.main() + else: + logging.info('Spotify data deemed to be recent enough (under {} seconds old)'.format(cache['expires_in'])) + +main() \ No newline at end of file diff --git a/process.py b/process.py index fcacc8e..891f631 100644 --- a/process.py +++ b/process.py @@ -1,5 +1,13 @@ +import os +import sys import json +def get_files(): + pass + +def process_track_file(data): + pass + def main(): saved_response = json.load(open('saved_tracks.json', 'r')) for track in saved_response['items']: