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
This commit is contained in:
Xevion
2019-12-21 02:34:11 -06:00
parent 2e4594138a
commit c87b9bdd7d
3 changed files with 5 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
from app import app from app import app
from config import Config
from flask import send_from_directory, redirect, url_for, render_template, send_file from flask import send_from_directory, redirect, url_for, render_template, send_file
import json import json
import subprocess import subprocess
@@ -21,10 +22,10 @@ def check_and_update():
else: else:
dif = time.time() - file['last_generated'] dif = time.time() - file['last_generated']
# print('dif', dif) # print('dif', dif)
if dif >= 3600: if dif >= Config.SPOTIFY_CACHE_TIME:
return True return True
else: else:
ideal = file['last_generated'] + 3600 ideal = file['last_generated'] + Config.SPOTIFY_CACHE_TIME
# print(f'Waiting another {int(ideal - time.time())} seconds') # print(f'Waiting another {int(ideal - time.time())} seconds')
return False return False

View File

@@ -11,7 +11,7 @@ import matplotlib.pyplot as plt
# Gets all files in tracks folder, returns them in parsed JSON # Gets all files in tracks folder, returns them in parsed JSON
def get_files(): def get_files():
folder = os.path.join(sys.path[0], 'tracks') folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tracks')
files = [] files = []
for file in os.listdir(folder): for file in os.listdir(folder):
with open(os.path.join(os.path.join(folder, file))) as file: with open(os.path.join(os.path.join(folder, file))) as file:

View File

@@ -4,6 +4,7 @@ basedir = os.path.abspath(os.path.dirname(__file__))
keys = json.load(open(os.path.join(basedir, 'keys.json'), 'r')) keys = json.load(open(os.path.join(basedir, 'keys.json'), 'r'))
class Config(object): class Config(object):
SPOTIFY_CACHE_TIME = 3600 # Number of seconds before the spotify-explicit program can be regenerated
REDDIT_SECRET = keys['REDDIT_SECRET'] REDDIT_SECRET = keys['REDDIT_SECRET']
DISCORD_TOKEN = keys['DISCORD_TOKEN'] DISCORD_TOKEN = keys['DISCORD_TOKEN']
SECRET_KEY = keys['SECRET_KEY'] SECRET_KEY = keys['SECRET_KEY']