99 lines
2.0 KiB
Python
99 lines
2.0 KiB
Python
|
from flask import Flask
|
||
|
from flask import render_template
|
||
|
from flask import request
|
||
|
from flask import g
|
||
|
import threading
|
||
|
from urllib import parse
|
||
|
import scripts.func as func
|
||
|
from scripts import database
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
|
||
|
def get_comics():
|
||
|
with app.app_context():
|
||
|
func.get_comics()
|
||
|
|
||
|
|
||
|
def verify_paths():
|
||
|
with app.app_context():
|
||
|
database.verify_paths()
|
||
|
|
||
|
|
||
|
with app.app_context():
|
||
|
database.initialize_db()
|
||
|
thread = threading.Thread(target=get_comics, args=())
|
||
|
thread.daemon = True
|
||
|
thread.start()
|
||
|
thread2 = threading.Thread(target=verify_paths, args=())
|
||
|
thread2.daemon = True
|
||
|
thread2.start()
|
||
|
|
||
|
|
||
|
@app.teardown_appcontext
|
||
|
def close_connection(exception):
|
||
|
db = getattr(g, '_database', None)
|
||
|
if db is not None:
|
||
|
db.close()
|
||
|
|
||
|
|
||
|
def update_comic_db(sender, **kw):
|
||
|
try:
|
||
|
database.add_comics(kw["meta"])
|
||
|
except Exception as e:
|
||
|
print(e)
|
||
|
|
||
|
|
||
|
func.comic_loaded.connect(update_comic_db)
|
||
|
|
||
|
|
||
|
@app.route('/')
|
||
|
def hello_world():
|
||
|
return render_template("index.html", title="Hello World")
|
||
|
|
||
|
|
||
|
@app.route("/movies")
|
||
|
def movies():
|
||
|
return "No Movies"
|
||
|
|
||
|
|
||
|
@app.route("/music")
|
||
|
def music():
|
||
|
return "No music"
|
||
|
|
||
|
|
||
|
@app.route("/games")
|
||
|
def games():
|
||
|
return "No Games"
|
||
|
|
||
|
|
||
|
@app.route("/comics")
|
||
|
def comics():
|
||
|
polling = request.args.get("polling")
|
||
|
|
||
|
if polling:
|
||
|
try:
|
||
|
return render_template("publisherList.html", comics=database.get_publishers())
|
||
|
except Exception as e:
|
||
|
print(e)
|
||
|
return "Sucks to be you"
|
||
|
try:
|
||
|
return render_template("publisherView.html", title="Comics", comics=database.get_publishers())
|
||
|
except Exception as e:
|
||
|
print(e)
|
||
|
|
||
|
|
||
|
@app.route("/comics/<publisher>")
|
||
|
def comics_publisher(publisher):
|
||
|
publisher = parse.unquote(publisher)
|
||
|
series = request.args.get("series")
|
||
|
series_year = request.args.get("seriesYear")
|
||
|
comic = request.args.get("comic")
|
||
|
if series:
|
||
|
return render_template("comicView.html", title="Comics", comics=database.db_get_comics_in_series(series, publisher, series_year))
|
||
|
return render_template("seriesView.html", title="Comics", comics=database.db_get_series_by_publisher(publisher))
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
app.run()
|