This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
60 lines (49 loc) · 1.5 KB
/
app.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import json
import logging
import sys
import webbrowser
from time import strftime
import waitress
from flask import request
from src import create_app, db
from src.anime.backup import delete_anime_export
from src.manga.backup import delete_manga_export
from src.settings.routes import create_json_files
app = create_app()
# This custom logging is taken from https://gist.github.com/alexaleluia12/e40f1dfa4ce598c2e958611f67d28966#file-flask_logging_requests-py-L28
@app.after_request
def after_request(response):
timestamp = strftime("[%Y-%b-%d %H:%M]")
logger.info(
"%s %s %s %s %s",
timestamp,
request.method,
request.scheme,
request.full_path,
response.status,
)
return response
def checks():
with app.app_context():
db.create_all()
create_json_files()
delete_anime_export()
delete_manga_export()
def run():
if sys.argv[-1].lower() == "super-saiyan":
app.run(host="127.0.0.1", port=6070, debug=True)
elif sys.argv[-1].lower() == "checks":
checks()
print("checks done!")
else:
print("Server running on http://127.0.0.1:6070")
webbrowser.open_new_tab("http://127.0.0.1:6070")
waitress.serve(app=app, host="127.0.0.1", port=6070)
if __name__ == "__main__":
checks()
with open("json/settings.json", "r") as f:
settings = json.load(f)
logger = logging.getLogger("tdm")
if settings["enable_logging"] == "Yes":
logger.setLevel(logging.INFO)
run()