created automated graph creation and delivery

This commit is contained in:
Xevion
2019-10-29 00:34:56 -05:00
parent c49a8260c0
commit 016ed5c6e8
5 changed files with 34 additions and 2 deletions

27
app/spotify.py Normal file
View File

@@ -0,0 +1,27 @@
from app import app
import json
import subprocess
import time
import os
from flask import send_from_directory, redirect, url_for, render_template, send_file
def check_and_update():
path = os.path.join('app/spotify_explicit/recent.json')
with open(path) as file:
try:
file = json.load(file)
except json.JSONDecodeError:
file = {'last_generated' : -1}
regen = time.time() - 3600 >= file['last_generated']
with open(path, 'w') as file:
file = json.dump({'last_generated' : int(time.time())}, file)
return regen
@app.route('/spotify/')
def spotify():
if check_and_update():
print('Graph out of date - running udpate command')
r = subprocess.run(['python', './app/spotify_explicit/main.py'], capture_output=True)
# return send_file('spotify_explicit/export/export.png')
return render_template('spotify.html')