From c87b9bdd7d76453d35e868f709eee2f279c74146 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 21 Dec 2019 02:34:11 -0600 Subject: [PATCH] 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 --- app/spotify.py | 5 +++-- app/spotify_explicit/process.py | 2 +- config.py | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/spotify.py b/app/spotify.py index 8eaeaac..5c9db35 100644 --- a/app/spotify.py +++ b/app/spotify.py @@ -1,4 +1,5 @@ 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 @@ -21,10 +22,10 @@ def check_and_update(): else: dif = time.time() - file['last_generated'] # print('dif', dif) - if dif >= 3600: + if dif >= Config.SPOTIFY_CACHE_TIME: return True else: - ideal = file['last_generated'] + 3600 + ideal = file['last_generated'] + Config.SPOTIFY_CACHE_TIME # print(f'Waiting another {int(ideal - time.time())} seconds') return False diff --git a/app/spotify_explicit/process.py b/app/spotify_explicit/process.py index c3d520e..47c277e 100644 --- a/app/spotify_explicit/process.py +++ b/app/spotify_explicit/process.py @@ -11,7 +11,7 @@ import matplotlib.pyplot as plt # Gets all files in tracks folder, returns them in parsed JSON def get_files(): - folder = os.path.join(sys.path[0], 'tracks') + folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tracks') files = [] for file in os.listdir(folder): with open(os.path.join(os.path.join(folder, file))) as file: diff --git a/config.py b/config.py index 28549ea..3e2645e 100644 --- a/config.py +++ b/config.py @@ -4,6 +4,7 @@ basedir = os.path.abspath(os.path.dirname(__file__)) keys = json.load(open(os.path.join(basedir, 'keys.json'), 'r')) class Config(object): + SPOTIFY_CACHE_TIME = 3600 # Number of seconds before the spotify-explicit program can be regenerated REDDIT_SECRET = keys['REDDIT_SECRET'] DISCORD_TOKEN = keys['DISCORD_TOKEN'] SECRET_KEY = keys['SECRET_KEY']