main refreshing work

This commit is contained in:
Xevion
2019-10-27 14:30:44 -05:00
parent 92b109241e
commit e6bb13c77d
2 changed files with 27 additions and 3 deletions

22
main.py
View File

@@ -7,6 +7,22 @@ import pull
import process import process
import logging import logging
cache = json.load(open(os.path.join(sys.path[0], f'.cache-{auth.username}'))) def main():
if time.time() > cache['expires_at']: logging.basicConfig(level=logging.INFO)
pull.main() 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()

View File

@@ -1,5 +1,13 @@
import os
import sys
import json import json
def get_files():
pass
def process_track_file(data):
pass
def main(): def main():
saved_response = json.load(open('saved_tracks.json', 'r')) saved_response = json.load(open('saved_tracks.json', 'r'))
for track in saved_response['items']: for track in saved_response['items']: