Files
v1.xevion.dev/app/spotify.py
Xevion c87b9bdd7d updated Spotify to have a CACHE TIME config constant var, moved tracks folder to export inside Spotify explicit folder
the tracks folder was relative of the main WSGI python file due to me using my sys.path[0] method of finding the current folder the file was in, unfortunately this ends up being unreliable when put into practice
2019-12-21 02:34:11 -06:00

39 lines
1.1 KiB
Python

from app import app
from config import Config
from flask import send_from_directory, redirect, url_for, render_template, send_file
import json
import subprocess
import time
import os
from .spotify_explicit import main
path = os.path.join('app/spotify_explicit/recent.json')
def check_and_update():
with open(path) as file:
try:
file = json.load(file)
except json.JSONDecodeError:
file = {'last_generated' : -1}
if file['last_generated'] == -1:
return True
else:
dif = time.time() - file['last_generated']
# print('dif', dif)
if dif >= Config.SPOTIFY_CACHE_TIME:
return True
else:
ideal = file['last_generated'] + Config.SPOTIFY_CACHE_TIME
# print(f'Waiting another {int(ideal - time.time())} seconds')
return False
@app.route('/spotify/')
def spotify():
if check_and_update():
print('Graph out of date - running update command')
with open(path, 'w') as file:
file = json.dump({'last_generated' : int(time.time())}, file)
main.main()
return send_file('spotify_explicit/export/export.png')