osu-wayback/web.py

45 lines
1.0 KiB
Python
Raw Normal View History

2018-01-12 23:16:10 +01:00
import json
import MySQLdb
import MySQLdb.cursors
2018-01-13 21:39:01 +01:00
from flask import Flask, make_response, request, render_template, jsonify
2018-05-31 11:18:23 +02:00
from handlers import getupdate, getfile, getlist
2018-05-29 13:28:42 +02:00
from objects import glob
2018-01-12 23:16:10 +01:00
app = Flask(__name__)
with open("config.json", "r") as f:
2018-05-23 22:59:21 +02:00
config = json.load(f)
2018-01-12 23:16:10 +01:00
2018-05-29 13:28:42 +02:00
# Setup sql
glob.sql = MySQLdb.connect(**config["sql"], cursorclass = MySQLdb.cursors.DictCursor)
2018-01-12 23:16:10 +01:00
@app.route("/")
2018-01-13 21:39:01 +01:00
@app.route("/home")
2018-01-12 23:16:10 +01:00
def home_index():
2018-05-23 22:59:21 +02:00
return render_template("index.html")
2018-01-12 23:16:10 +01:00
2018-01-13 21:39:01 +01:00
@app.route("/download")
def download_index():
2018-05-23 22:59:21 +02:00
return render_template("download.html")
@app.route("/api")
def api_index():
return render_template("api.html")
@app.route("/api/getUpdate", methods=["GET", "POST"])
def api_update():
2018-05-31 10:59:36 +02:00
data = getupdate.handle(request)
2018-05-31 10:59:10 +02:00
return jsonify(data)
2018-01-13 21:39:01 +01:00
2018-05-29 13:38:35 +02:00
@app.route("/api/getFile", methods=["GET", "POST"])
def api_file():
2018-05-31 10:59:36 +02:00
data = getfile.handle(request)
2018-05-31 10:59:10 +02:00
return jsonify(data)
2018-05-29 13:38:35 +02:00
2018-05-31 11:18:23 +02:00
@app.route("/api/getList", methods=["GET", "POST"])
def api_list():
data = getlist.handle(request)
return jsonify(data)
2018-01-12 23:16:10 +01:00
if __name__ == "__main__":
2018-05-23 22:59:21 +02:00
app.run(**config["web"])