forked from boisdal/jukebox-ultra-nrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
40 lines (36 loc) · 1.5 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from jukebox import app
import os
if __name__ == "__main__":
# cleanup leftovers
if os.path.exists("mpv.socket"):
os.remove("mpv.socket")
temp_download_path = app.config["TEMP_DOWNLOAD_PATH"]
if os.path.isfile(temp_download_path):
os.remove(temp_download_path)
if not os.path.exists(temp_download_path):
os.makedirs(temp_download_path)
for file in os.listdir(temp_download_path):
os.remove(temp_download_path + file)
# create database if it doesn't exists
if not os.path.exists(app.config["DATABASE_PATH"]):
app.logger.info("Database nonexistent, creating schema")
with app.database_lock:
import sqlite3
conn = sqlite3.connect(app.config["DATABASE_PATH"])
c = conn.cursor()
path_sql = "jukebox/src/sql-schemas/"
with open(path_sql + "schema-users.sql", 'r') as f:
schema_users = f.read()
c.execute(schema_users)
with open(path_sql + "schema-log.sql", 'r') as f:
schema_log = f.read()
c.execute(schema_log)
with open(path_sql + "schema-track-info.sql", 'r') as f:
schema_track_info = f.read()
c.execute(schema_track_info)
conn.commit()
conn.close()
# run the flask app
app.secret_key = "ThisMightBeThePlaceToSetTheSecretKey"
# It's actually not used at all, so who cares
app.run(host=app.config["LISTEN_ADDR"], port=app.config["LISTEN_PORT"])