1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Add game pages

This commit is contained in:
Steffo 2018-06-13 23:32:26 +02:00
parent 6df508ece3
commit 5552c92817
12 changed files with 199 additions and 140 deletions

4
db.py
View file

@ -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.")
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"]

16
templates/game.html Normal file
View file

@ -0,0 +1,16 @@
{% extends 'base.html' %}
{% block pagetitle %}
{{ game_name }}
{% endblock %}
{% block body %}
<h1>
Royal Games su {{ game_name }}
</h1>
{% for mini in minis %}
{% with record = mini %}
{% include "minis/" + game_short_name + ".html" %}
{% endwith %}
{% endfor %}
{% endblock %}

View file

@ -9,27 +9,27 @@
<div class="game-panel">
<div class="game-grid dota">
<div class="player">
<a href="https://www.opendota.com/players/{{ dota.steam.to_steam_id_3(dota.steam.steam_id) }}">
<img src="{{ dota.steam.avatar_url() }}" class="player-image">
<span class="player-name">{{ dota.steam.persona_name }}</span>
<a href="https://www.opendota.com/players/{{ record.steam.to_steam_id_3(record.steam.steam_id) }}">
<img src="{{ record.steam.avatar_url() }}" class="player-image">
<span class="player-name">{{ record.steam.persona_name }}</span>
</a>
</div>
<div class="game-title wins">
Vittorie
</div>
<div class="game-score wins">
<span>{{ dota.wins }}</span>
<span>{{ record.wins }}</span>
</div>
<div class="rank">
{% if dota.rank_tier is none %}
{% if record.rank_tier is none %}
<img class="medal" src="https://www.opendota.com/assets/images/dota2/rank_icons/rank_icon_0.png">
<span class="text">Non classificato</span>
{% elif dota.rank_tier < 10 %}
{% elif record.rank_tier < 10 %}
<img class="medal" src="https://www.opendota.com/assets/images/dota2/rank_icons/rank_icon_0.png">
<span class="text">{{ dota.rank_tier }} piazzamenti completati</span>
<span class="text">{{ record.rank_tier }} piazzamenti completati</span>
{% else %}
<img class="medal" src="{{ dota.get_rank_icon_url() }}">{% if dota.get_rank_stars_url() %}<img class="stars" src="{{ dota.get_rank_stars_url() }}">{% endif %}
<span class="text">{{ dota.get_rank_name() }}[{{ dota.get_rank_number() }}]</span>
<img class="medal" src="{{ record.get_rank_icon_url() }}">{% if record.get_rank_stars_url() %}<img class="stars" src="{{ record.get_rank_stars_url() }}">{% endif %}
<span class="text">{{ record.get_rank_name() }}[{{ record.get_rank_number() }}]</span>
{% endif %}
</div>
</div>

View file

@ -1,49 +1,49 @@
<style>
@font-face {
font-family: "BeaufortLoL";
src: url("{{ url_for('static', filename='beaufortlol.woff') }}") format('woff');
src: url("{{ url_for('static', filename='beaufortrecord.woff') }}") format('woff');
}
</style>
<div class="game-panel">
<div class="game-grid lol">
<div class="player">
<img src="http://avatar.leagueoflegends.com/EUW1/{{ lol.summoner_name }}.png" class="player-image">
<span class="player-name">{{ lol.summoner_name }}</span>
<img src="http://avatar.leagueoflegends.com/EUW1/{{ record.summoner_name }}.png" class="player-image">
<span class="player-name">{{ record.summoner_name }}</span>
</div>
<div class="game-title level">
LIVELLO
</div>
<div class="game-score level">
<span>{{ lol.level }}</span>
<span>{{ record.level }}</span>
</div>
<div class="game-title soloq">
SOLO/DUO
</div>
<div class="game-score soloq">
{% if lol.solo_division is none %}
{% if record.solo_division is none %}
<img src="{{ url_for('static', filename='lol-rank-icons/provisional.png') }}" title="Non classificato" class="rank">
{% else %}
<img src="{{ url_for('static', filename='lol-rank-icons/' + lol.solo_division.name|lower + "_" + lol.solo_rank.name|lower + ".png") }}" class="rank" title="{{ lol.solo_division.name|capitalize }} {{ lol.solo_rank.name }}">
<img src="{{ url_for('static', filename='lol-rank-icons/' + record.solo_division.name|lower + "_" + record.solo_rank.name|lower + ".png") }}" class="rank" title="{{ record.solo_division.name|capitalize }} {{ record.solo_rank.name }}">
{% endif %}
</div>
<div class="game-title flexq">
FLEX
</div>
<div class="game-score flexq">
{% if lol.flex_division is none %}
{% if record.flex_division is none %}
<img src="{{ url_for('static', filename='lol-rank-icons/provisional.png') }}" title="Non classificato" class="rank">
{% else %}
<img src="{{ url_for('static', filename='lol-rank-icons/' + lol.flex_division.name|lower + "_" + lol.flex_rank.name|lower + ".png") }}" class="rank" title="{{ lol.flex_division.name|capitalize }} {{ lol.flex_rank.name }}">
<img src="{{ url_for('static', filename='lol-rank-icons/' + record.flex_division.name|lower + "_" + record.flex_rank.name|lower + ".png") }}" class="rank" title="{{ record.flex_division.name|capitalize }} {{ record.flex_rank.name }}">
{% endif %}
</div>
<div class="game-title twtrq">
3V3
</div>
<div class="game-score twtrq">
{% if lol.twtr_division is none %}
{% if record.twtr_division is none %}
<img src="{{ url_for('static', filename='lol-rank-icons/provisional.png') }}" title="Non classificato" class="rank">
{% else %}
<img src="{{ url_for('static', filename='lol-rank-icons/' + lol.twtr_division.name|lower + "_" + lol.twtr_rank.name|lower + ".png") }}" class="rank" title="{{ lol.twtr_division.name|capitalize }} {{ lol.twtr_rank.name }}">
<img src="{{ url_for('static', filename='lol-rank-icons/' + record.twtr_division.name|lower + "_" + record.twtr_rank.name|lower + ".png") }}" class="rank" title="{{ record.twtr_division.name|capitalize }} {{ record.twtr_rank.name }}">
{% endif %}
</div>
</div>

View file

@ -3,34 +3,34 @@
<div class="background-image"></div>
<div class="background-color"></div>
<div class="player">
<a href="https://osu.ppy.sh/users/{{ osu.osu_id }}">
<img src="https://a.ppy.sh/{{ osu.osu_id }}" class="player-image">
<span class="player-name">{{ osu.osu_name }}</span>
<a href="https://record.ppy.sh/users/{{ record.osu_id }}">
<img src="https://a.ppy.sh/{{ record.osu_id }}" class="player-image">
<span class="player-name">{{ record.osu_name }}</span>
</a>
</div>
<div class="game-title standard">
osu!
</div>
<div class="game-score standard">
<span class="number">{{ osu.std_pp | int }}</span><span class="pp">pp</span>
<span class="number">{{ record.std_pp | int }}</span><span class="pp">pp</span>
</div>
<div class="game-title taiko">
osu!taiko
</div>
<div class="game-score taiko">
<span class="number">{{ osu.taiko_pp | int }}</span><span class="pp">pp</span>
<span class="number">{{ record.taiko_pp | int }}</span><span class="pp">pp</span>
</div>
<div class="game-title catch">
osu!catch
</div>
<div class="game-score catch">
<span class="number">{{ osu.catch_pp | int }}</span><span class="pp">pp</span>
<span class="number">{{ record.catch_pp | int }}</span><span class="pp">pp</span>
</div>
<div class="game-title mania">
osu!mania
</div>
<div class="game-score mania">
<span class="number">{{ osu.mania_pp | int }}</span><span class="pp">pp</span>
<span class="number">{{ record.mania_pp | int }}</span><span class="pp">pp</span>
</div>
</div>
</div>

View file

@ -9,24 +9,24 @@
<div class="game-panel">
<div class="game-grid ow">
<div class="player">
<a href="https://playoverwatch.com/en-us/career/pc/eu/{{ ow.__str__(separator='-') }}">
<img src="{{ ow.icon_url() }}" class="player-image">
<span class="player-name">{{ ow }}</span>
<a href="https://playoverwatch.com/en-us/career/pc/eu/{{ record.__str__(separator='-') }}">
<img src="{{ record.icon_url() }}" class="player-image">
<span class="player-name">{{ record }}</span>
</a>
</div>
<div class="game-title level">
Livello
</div>
<div class="game-score level">
<span>{{ ow.level }}</span>
<span>{{ record.level }}</span>
</div>
<div class="rank">
{% if ow.rank is none %}
{% if record.rank is none %}
<div class="icon unranked"></div>
<span class="text unranked">Non classificato</span>
{% else %}
<img class="icon ranked" src="{{ ow.rank_url() }}">
<span class="text ranked">{{ ow.rank }}</span>
<img class="icon ranked" src="{{ record.rank_url() }}">
<span class="text ranked">{{ record.rank }}</span>
{% endif %}
</div>
</div>

View file

@ -4,34 +4,34 @@
<div class="game-panel">
<div class="game-grid rl">
<div class="player">
<a href="https://rocketleaguestats.com/profile/steam/{{ rl.steam.steam_id }}">
<img src="{{ rl.steam.avatar_url() }}" class="player-image">
<span class="player-name">{{ rl.steam.persona_name }}</span>
<a href="https://rocketleaguestats.com/profile/steam/{{ record.steam.steam_id }}">
<img src="{{ record.steam.avatar_url() }}" class="player-image">
<span class="player-name">{{ record.steam.persona_name }}</span>
</a>
</div>
<div class="game-title duel">
DUELLO
</div>
<div class="game-score duel">
<img src="{{ rl.solo_rank_image() }}" title="{{ rl.single_mmr }} MMR">
<img src="{{ record.solo_rank_image() }}" title="{{ record.single_mmr }} MMR">
</div>
<div class="game-title doubles">
DOPPIO
</div>
<div class="game-score doubles">
<img src="{{ rl.doubles_rank_image() }}" title="{{ rl.doubles_mmr }} MMR">
<img src="{{ record.doubles_rank_image() }}" title="{{ record.doubles_mmr }} MMR">
</div>
<div class="game-title standard">
STANDARD
</div>
<div class="game-score standard">
<img src="{{ rl.standard_rank_image() }}" title="{{ rl.standard_mmr }} MMR">
<img src="{{ record.standard_rank_image() }}" title="{{ record.standard_mmr }} MMR">
</div>
<div class="game-title solostd">
SOLO STD
</div>
<div class="game-score solostd">
<img src="{{ rl.solo_std_rank_image() }}" title="{{ rl.solo_std_mmr }} MMR">
<img src="{{ record.solo_std_rank_image() }}" title="{{ record.solo_std_mmr }} MMR">
</div>
</div>
</div>

View file

@ -1,16 +1,16 @@
<div class="game-panel">
<div class="game-grid ryg">
<div class="player">
<span class="player-name">{{ royal.username }}</span>
<span class="player-name">{{ record.username }}</span>
</div>
<div class="member-status">
<span class="role">{{ royal.role }}</span> dal <span class="member-since">{% if royal.member_since %}{{ royal.member_since }}{% else %}????-??-??{% endif %}</span>
<span class="role">{{ record.role }}</span> dal <span class="member-since">{% if record.member_since %}{{ record.member_since }}{% else %}????-??-??{% endif %}</span>
</div>
<div class="game-title fiorygi">
Fiorygi
</div>
<div class="game-score fiorygi">
{{ royal.fiorygi }}
{{ record.fiorygi }}
</div>
</div>
</div>

View file

@ -5,39 +5,39 @@
<div class="game-panel">
<div class="game-grid steam">
<div class="player">
<a href="http://steamcommunity.com/profiles/{{ steam.steam_id }}">
<img src="{{ steam.avatar_url() }}" class="player-image">
<span class="player-name">{{ steam.persona_name }}</span>
<a href="http://steamcommunity.com/profiles/{{ record.steam_id }}">
<img src="{{ record.avatar_url() }}" class="player-image">
<span class="player-name">{{ record.persona_name }}</span>
</a>
</div>
<div class="buttons">
<a href="steam://friends/add/{{ steam.steam_id }}">
<a href="steam://friends/add/{{ record.steam_id }}">
<div class="button add-friend-button">
<i class="fas fa-user-plus"></i>
</div>
</a>
<a href="steam://friends/message/{{ steam.steam_id }}">
<a href="steam://friends/message/{{ record.steam_id }}">
<div class="button message-button">
<i class="fas fa-comment-alt"></i>
</div>
</a>
<a href="https://steamdb.info/calculator/{{ steam.steam_id }}" target="_blank">
<a href="https://steamdb.info/calculator/{{ record.steam_id }}" target="_blank">
<div class="button calculator-button">
<i class="fas fa-calculator"></i>
</div>
</a>
{% if steam.trade_token %}
<a href="{{ steam.trade_token }}" target="_blank">
{% if record.trade_token %}
<a href="{{ record.trade_token }}" target="_blank">
<div class="button trade-button">
<i class="fas fa-handshake"></i>
</div>
</a>
{% endif %}
</div>
{% if steam.most_played_game_id %}
<a href="https://store.steampowered.com/app/{{ steam.most_played_game_id }}/">
{% if record.most_played_game_id %}
<a href="https://store.steampowered.com/app/{{ record.most_played_game_id }}/">
<div class="game-banner">
<img src="https://steamcdn-a.akamaihd.net/steam/apps/{{ steam.most_played_game_id }}/header.jpg">
<img src="https://steamcdn-a.akamaihd.net/steam/apps/{{ record.most_played_game_id }}/header.jpg">
</div>
</a>
{% endif %}

View file

@ -20,21 +20,33 @@
</h1>
{% include "minis/ryg.html" %}
{% if steam %}
{% with record = steam %}
{% include "minis/steam.html" %}
{% endwith %}
{% endif %}
{% if rl %}
{% with record = rl %}
{% include "minis/rl.html" %}
{% endwith %}
{% endif %}
{% if dota %}
{% with record = dota %}
{% include "minis/dota.html" %}
{% endwith %}
{% endif %}
{% if osu %}
{% with record = osu %}
{% include "minis/osu.html" %}
{% endwith %}
{% endif %}
{% if lol %}
{% with record = lol %}
{% include "minis/lol.html" %}
{% endwith %}
{% endif %}
{% if ow %}
{% with record = ow %}
{% include "minis/ow.html" %}
{% endwith %}
{% endif %}
{% endblock %}

158
update.py
View file

@ -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():

View file

@ -123,6 +123,33 @@ def page_setcss():
return redirect(url_for("page_profile", name=royal.username))
@app.route("/game/<name>")
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__)