From 5552c92817bbbcdd05c571cb73aed7de45427ac4 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 13 Jun 2018 23:32:26 +0200 Subject: [PATCH] Add game pages --- db.py | 6 +- templates/game.html | 16 ++++ templates/minis/dota.html | 18 ++--- templates/minis/lol.html | 20 ++--- templates/minis/osu.html | 14 ++-- templates/minis/ow.html | 14 ++-- templates/minis/rl.html | 14 ++-- templates/minis/ryg.html | 6 +- templates/minis/steam.html | 22 +++--- templates/profile.html | 24 ++++-- update.py | 158 ++++++++++++++++++------------------- webserver.py | 27 +++++++ 12 files changed, 199 insertions(+), 140 deletions(-) create mode 100644 templates/game.html diff --git a/db.py b/db.py index d8439399..081c4649 100644 --- a/db.py +++ b/db.py @@ -167,6 +167,7 @@ class Steam(Base): raise RequestError(f"Game data is private") self.most_played_game_id = j["response"]["games"][0]["appid"] + class RocketLeague(Base): __tablename__ = "rocketleague" @@ -637,7 +638,10 @@ class Overwatch(Base): j = r.json()["eu"]["stats"]["quickplay"]["overall_stats"] except TypeError: raise RequestError("Something went wrong when retrieving the stats.") - self.icon = re.search(r"https://.+\.cloudfront\.net/game/unlocks/(0x[0-9A-F]+)\.png", j["avatar"]).group(1) + try: + self.icon = re.search(r"https://.+\.cloudfront\.net/game/unlocks/(0x[0-9A-F]+)\.png", j["avatar"]).group(1) + except AttributeError: + pass self.level = j["prestige"] * 100 + j["level"] self.rank = j["comprank"] diff --git a/templates/game.html b/templates/game.html new file mode 100644 index 00000000..ed482fb5 --- /dev/null +++ b/templates/game.html @@ -0,0 +1,16 @@ +{% extends 'base.html' %} + +{% block pagetitle %} + {{ game_name }} +{% endblock %} + +{% block body %} +

+ Royal Games su {{ game_name }} +

+ {% for mini in minis %} + {% with record = mini %} + {% include "minis/" + game_short_name + ".html" %} + {% endwith %} + {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/templates/minis/dota.html b/templates/minis/dota.html index dcebfce1..962f359d 100644 --- a/templates/minis/dota.html +++ b/templates/minis/dota.html @@ -9,27 +9,27 @@
Vittorie
- {{ dota.wins }} + {{ record.wins }}
- {% if dota.rank_tier is none %} + {% if record.rank_tier is none %} Non classificato - {% elif dota.rank_tier < 10 %} + {% elif record.rank_tier < 10 %} - {{ dota.rank_tier }} piazzamenti completati + {{ record.rank_tier }} piazzamenti completati {% else %} - {% if dota.get_rank_stars_url() %}{% endif %} - {{ dota.get_rank_name() }}[{{ dota.get_rank_number() }}] + {% if record.get_rank_stars_url() %}{% endif %} + {{ record.get_rank_name() }}[{{ record.get_rank_number() }}] {% endif %}
diff --git a/templates/minis/lol.html b/templates/minis/lol.html index c49e0d3e..2932254c 100644 --- a/templates/minis/lol.html +++ b/templates/minis/lol.html @@ -1,49 +1,49 @@
- - {{ lol.summoner_name }} + + {{ record.summoner_name }}
LIVELLO
- {{ lol.level }} + {{ record.level }}
SOLO/DUO
- {% if lol.solo_division is none %} + {% if record.solo_division is none %} {% else %} - + {% endif %}
FLEX
- {% if lol.flex_division is none %} + {% if record.flex_division is none %} {% else %} - + {% endif %}
3V3
- {% if lol.twtr_division is none %} + {% if record.twtr_division is none %} {% else %} - + {% endif %}
diff --git a/templates/minis/osu.html b/templates/minis/osu.html index 37e3e821..aee4d2ad 100644 --- a/templates/minis/osu.html +++ b/templates/minis/osu.html @@ -3,34 +3,34 @@
osu!
- {{ osu.std_pp | int }}pp + {{ record.std_pp | int }}pp
osu!taiko
- {{ osu.taiko_pp | int }}pp + {{ record.taiko_pp | int }}pp
osu!catch
- {{ osu.catch_pp | int }}pp + {{ record.catch_pp | int }}pp
osu!mania
- {{ osu.mania_pp | int }}pp + {{ record.mania_pp | int }}pp
\ No newline at end of file diff --git a/templates/minis/ow.html b/templates/minis/ow.html index 6a9eb96e..71f98482 100644 --- a/templates/minis/ow.html +++ b/templates/minis/ow.html @@ -9,24 +9,24 @@
Livello
- {{ ow.level }} + {{ record.level }}
- {% if ow.rank is none %} + {% if record.rank is none %}
Non classificato {% else %} - - {{ ow.rank }} + + {{ record.rank }} {% endif %}
diff --git a/templates/minis/rl.html b/templates/minis/rl.html index 8f7ecc73..a25d8318 100644 --- a/templates/minis/rl.html +++ b/templates/minis/rl.html @@ -4,34 +4,34 @@
DUELLO
- +
DOPPIO
- +
STANDARD
- +
SOLO STD
- +
\ No newline at end of file diff --git a/templates/minis/ryg.html b/templates/minis/ryg.html index baa781bf..f45153cf 100644 --- a/templates/minis/ryg.html +++ b/templates/minis/ryg.html @@ -1,16 +1,16 @@
- {{ royal.username }} + {{ record.username }}
- {{ royal.role }} dal {% if royal.member_since %}{{ royal.member_since }}{% else %}????-??-??{% endif %} + {{ record.role }} dal {% if record.member_since %}{{ record.member_since }}{% else %}????-??-??{% endif %}
Fiorygi
- {{ royal.fiorygi }} + {{ record.fiorygi }}
\ No newline at end of file diff --git a/templates/minis/steam.html b/templates/minis/steam.html index 3e6909ef..7d66557c 100644 --- a/templates/minis/steam.html +++ b/templates/minis/steam.html @@ -5,39 +5,39 @@
- +
- +
- +
- {% if steam.trade_token %} - + {% if record.trade_token %} +
{% endif %}
- {% if steam.most_played_game_id %} - + {% if record.most_played_game_id %} +
- +
{% endif %} diff --git a/templates/profile.html b/templates/profile.html index 8c528f2d..db10a27e 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -20,21 +20,33 @@ {% include "minis/ryg.html" %} {% if steam %} - {% include "minis/steam.html" %} + {% with record = steam %} + {% include "minis/steam.html" %} + {% endwith %} {% endif %} {% if rl %} - {% include "minis/rl.html" %} + {% with record = rl %} + {% include "minis/rl.html" %} + {% endwith %} {% endif %} {% if dota %} - {% include "minis/dota.html" %} + {% with record = dota %} + {% include "minis/dota.html" %} + {% endwith %} {% endif %} {% if osu %} - {% include "minis/osu.html" %} + {% with record = osu %} + {% include "minis/osu.html" %} + {% endwith %} {% endif %} {% if lol %} - {% include "minis/lol.html" %} + {% with record = lol %} + {% include "minis/lol.html" %} + {% endwith %} {% endif %} {% if ow %} - {% include "minis/ow.html" %} + {% with record = ow %} + {% include "minis/ow.html" %} + {% endwith %} {% endif %} {% endblock %} \ No newline at end of file diff --git a/update.py b/update.py index 232e37a8..a44962dc 100644 --- a/update.py +++ b/update.py @@ -8,85 +8,85 @@ try: while True: session = db.Session() # Update Steam - print("STEAM") - for user in session.query(db.Steam).all(): - t = time.clock() - print(f"Updating {user.royal.username}", end="\t\t", flush=True) - try: - user.update() - except errors.RequestError: - print("Request Error") - except errors.NotFoundError: - print("Not Found Error (?)") - else: - print("OK") - finally: - sleep_time = 1 - time.clock() + t - time.sleep(sleep_time if sleep_time > 0 else 0) - # Update Rocket League - print("ROCKET LEAGUE") - for user in session.query(db.RocketLeague).all(): - t = time.clock() - print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True) - try: - user.update() - except errors.RequestError: - print("Request Error") - except errors.NotFoundError: - print("Not Found Error (?)") - else: - print("OK") - finally: - sleep_time = 1 - time.clock() + t - time.sleep(sleep_time if sleep_time > 0 else 0) - # Update Dota 2 - print("DOTA 2") - for user in session.query(db.Dota).all(): - t = time.clock() - print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True) - try: - user.update() - except errors.RequestError: - print("Request Error") - except errors.NotFoundError: - print("Not Found Error (?)") - else: - print("OK") - finally: - sleep_time = 1 - time.clock() + t - time.sleep(sleep_time if sleep_time > 0 else 0) - # Update League of Legends - print("LEAGUE OF LEGENDS") - for user in session.query(db.LeagueOfLegends).all(): - t = time.clock() - print(f"Updating {user.royal.username}", end="\t\t", flush=True) - try: - user.update() - except errors.RequestError: - print("Request Error") - except errors.NotFoundError: - print("Not Found Error (?)") - else: - print("OK") - finally: - sleep_time = 1 - time.clock() + t - time.sleep(sleep_time if sleep_time > 0 else 0) - # Update Osu! - print("OSU!") - for user in session.query(db.Osu).all(): - t = time.clock() - print(f"Updating {user.royal.username}", end="\t\t", flush=True) - try: - user.update() - except errors.RequestError: - print("Request Error") - except errors.NotFoundError: - print("Not Found Error (?)") - else: - print("OK") - finally: - sleep_time = 1 - time.clock() + t - time.sleep(sleep_time if sleep_time > 0 else 0) + #print("STEAM") + #for user in session.query(db.Steam).all(): + # t = time.clock() + # print(f"Updating {user.royal.username}", end="\t\t", flush=True) + # try: + # user.update() + # except errors.RequestError: + # print("Request Error") + # except errors.NotFoundError: + # print("Not Found Error (?)") + # else: + # print("OK") + # finally: + # sleep_time = 1 - time.clock() + t + # time.sleep(sleep_time if sleep_time > 0 else 0) + ## Update Rocket League + #print("ROCKET LEAGUE") + #for user in session.query(db.RocketLeague).all(): + # t = time.clock() + # print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True) + # try: + # user.update() + # except errors.RequestError: + # print("Request Error") + # except errors.NotFoundError: + # print("Not Found Error (?)") + # else: + # print("OK") + # finally: + # sleep_time = 1 - time.clock() + t + # time.sleep(sleep_time if sleep_time > 0 else 0) + ## Update Dota 2 + #print("DOTA 2") + #for user in session.query(db.Dota).all(): + # t = time.clock() + # print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True) + # try: + # user.update() + # except errors.RequestError: + # print("Request Error") + # except errors.NotFoundError: + # print("Not Found Error (?)") + # else: + # print("OK") + # finally: + # sleep_time = 1 - time.clock() + t + # time.sleep(sleep_time if sleep_time > 0 else 0) + ## Update League of Legends + #print("LEAGUE OF LEGENDS") + #for user in session.query(db.LeagueOfLegends).all(): + # t = time.clock() + # print(f"Updating {user.royal.username}", end="\t\t", flush=True) + # try: + # user.update() + # except errors.RequestError: + # print("Request Error") + # except errors.NotFoundError: + # print("Not Found Error (?)") + # else: + # print("OK") + # finally: + # sleep_time = 1 - time.clock() + t + # time.sleep(sleep_time if sleep_time > 0 else 0) + ## Update Osu! + #print("OSU!") + #for user in session.query(db.Osu).all(): + # t = time.clock() + # print(f"Updating {user.royal.username}", end="\t\t", flush=True) + # try: + # user.update() + # except errors.RequestError: + # print("Request Error") + # except errors.NotFoundError: + # print("Not Found Error (?)") + # else: + # print("OK") + # finally: + # sleep_time = 1 - time.clock() + t + # time.sleep(sleep_time if sleep_time > 0 else 0) # Update Overwatch print("OVERWATCH") for user in session.query(db.Overwatch).all(): diff --git a/webserver.py b/webserver.py index 90ace384..b32d8780 100644 --- a/webserver.py +++ b/webserver.py @@ -123,6 +123,33 @@ def page_setcss(): return redirect(url_for("page_profile", name=royal.username)) +@app.route("/game/") +def page_game(name: str): + db_session = db.Session() + if name == "rl": + game_name = "Rocket League" + query = db_session.query(db.RocketLeague).join(db.Steam).all() + elif name == "dota": + game_name = "Dota 2" + query = db_session.query(db.Dota).join(db.Steam).all() + elif name == "lol": + game_name = "League of Legends" + query = db_session.query(db.LeagueOfLegends).all() + elif name == "osu": + game_name = "osu!" + query = db_session.query(db.Osu).all() + elif name == "ow": + game_name = "Overwatch" + query = db_session.query(db.Overwatch).all() + elif name == "steam": + game_name = "Steam" + query = db_session.query(db.Steam).all() + elif name == "ryg": + game_name = "Royalnet" + query = db_session.query(db.Royal).all() + db_session.close() + return render_template("game.html", minis=query, game_name=game_name, game_short_name=name) + if __name__ == "__main__": try: app.run(host="0.0.0.0", port=1234, debug=__debug__)