diff --git a/db.py b/db.py index 5f19be4b..3243cd88 100644 --- a/db.py +++ b/db.py @@ -257,7 +257,7 @@ class Dota(Base): if r.status_code != 200: raise RequestError("OpenDota returned {r.status_code}") data = r.json() - r = requests.get(f"https://api.opendota.com/api/players/{Steam.to_steam_id_3(steam_id)}/wl") + r = requests.get(f"https://api.opendota.com/api/players/{Steam.to_steam_id_3(self.steam_id)}/wl") if r.status_code != 200: raise RequestError("OpenDota returned {r.status_code}") wl = r.json() @@ -408,10 +408,10 @@ class Osu(Base): return new_record def update(self): - r0 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={osu_name}&m=0") - r1 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={osu_name}&m=1") - r2 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={osu_name}&m=2") - r3 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={osu_name}&m=3") + r0 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=0") + r1 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=1") + r2 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=2") + r3 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=3") if r0.status_code != 200 or r1.status_code != 200 or r2.status_code != 200 or r3.status_code != 200: raise RequestError( f"Osu! API returned an error ({r0.status_code} {r1.status_code} {r2.status_code} {r3.status_code})") @@ -429,11 +429,3 @@ class Osu(Base): # If run as script, create all the tables in the db if __name__ == "__main__": Base.metadata.create_all(bind=engine) - for player in session.query(Royal).all(): - name = input(f"{player}: ") - if name == "": - continue - o = Osu.get_or_create(player.id, name) - print(o) - session.add(o) - session.commit() \ No newline at end of file diff --git a/flaskserver.py b/flaskserver.py new file mode 100644 index 00000000..b389a89a --- /dev/null +++ b/flaskserver.py @@ -0,0 +1,29 @@ +import db +from flask import Flask, render_template + +app = Flask(__name__) + +@app.route("/dota/ladder") +def page_dota_ladder(): + session = db.Session() + query = session.execute("SELECT royals.username, dota.solo_mmr, dota.party_mmr, dota.wins FROM royals JOIN steam ON royals.id = steam.royal_id JOIN dota ON steam.steam_id = dota.steam_id ORDER BY dota.solo_mmr DESC;") + return render_template("table.htm", query=query) + + +@app.route("/rl/ladder") +def page_rl_ladder(): + session = db.Session() + query = session.execute("SELECT royals.username, rocketleague.single_mmr, rocketleague.doubles_mmr, rocketleague.standard_mmr, rocketleague.solo_std_mmr FROM royals JOIN steam ON royals.id = steam.royal_id JOIN rocketleague ON steam.steam_id = rocketleague.steam_id ORDER BY rocketleague.doubles_mmr DESC;") + return render_template("table.htm", query=query) + + +@app.route("/osu/ladder") +def page_osu_ladder(): + session = db.Session() + query = session.execute("SELECT royals.username, osu.std_pp, osu.taiko_pp, osu.catch_pp, osu.mania_pp FROM royals JOIN osu ON royals.id = osu.royal_id ORDER BY osu.std_pp DESC;") + return render_template("table.htm", query=query) + + + +if __name__ == "__main__": + app.run() \ No newline at end of file diff --git a/templates/table.htm b/templates/table.htm new file mode 100644 index 00000000..5b6cf244 --- /dev/null +++ b/templates/table.htm @@ -0,0 +1,36 @@ + + +
+ + ++ {{ column }} + | + {% endfor %} +
---|
+ {% if column %} + {{ column }} + {% endif %} + | + {% endfor %} +