diff --git a/.gitignore b/.gitignore index 246e919..fbb9cc6 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ key /__pycache__/* app/static/token.dat .vscode/* -keys.json \ No newline at end of file +keys.json +.cache-xevioni \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index 2f55c31..5b465ed 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -16,5 +16,7 @@ db = SQLAlchemy(app) migrate = Migrate(app, db) from app import models -from app import routes, simple_routes, hidden, dashboard, ftbhot, custom +from app import routes, simple_routes, hidden, dashboard +from app import ftbhot, custom, spotify + app.jinja_env.globals.update(get_hidden=routes.get_hidden) \ No newline at end of file diff --git a/app/spotify.py b/app/spotify.py new file mode 100644 index 0000000..0de37b0 --- /dev/null +++ b/app/spotify.py @@ -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') \ No newline at end of file diff --git a/app/spotify_explicit b/app/spotify_explicit new file mode 160000 index 0000000..9bd5b0c --- /dev/null +++ b/app/spotify_explicit @@ -0,0 +1 @@ +Subproject commit 9bd5b0c7897ae1214d982c751c7e5e32e1678a21 diff --git a/app/templates/spotify.html b/app/templates/spotify.html new file mode 100644 index 0000000..9227cc4 --- /dev/null +++ b/app/templates/spotify.html @@ -0,0 +1 @@ + \ No newline at end of file