1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Disable Rocket League after the API shutdown

This commit is contained in:
Steffo 2018-08-16 16:25:05 +02:00
parent 905e11bda3
commit 0ee007a906
5 changed files with 87 additions and 87 deletions

134
db.py
View file

@ -198,74 +198,74 @@ class RocketLeague(Base):
def __repr__(self):
return f"<RocketLeague {self.steam_id}>"
@staticmethod
def create(session: Session, steam_id: str):
rl = session.query(RocketLeague).get(steam_id)
if rl is not None:
raise AlreadyExistingError(repr(rl))
r = requests.get(f"https://api.rocketleaguestats.com/v1/player?apikey={config['Rocket League']['rlstats_api_key']}&unique_id={str(steam_id)}&platform_id=1")
if r.status_code == 404:
raise NotFoundError("The specified user has never played Rocket League")
elif r.status_code != 200:
raise RequestError("Rocket League Stats returned {r.status_code}")
new_record = RocketLeague(steam_id=steam_id)
new_record.update(data=r.json())
return new_record
# @staticmethod
# def create(session: Session, steam_id: str):
# rl = session.query(RocketLeague).get(steam_id)
# if rl is not None:
# raise AlreadyExistingError(repr(rl))
# r = requests.get(f"https://api.rocketleaguestats.com/v1/player?apikey={config['Rocket League']['rlstats_api_key']}&unique_id={str(steam_id)}&platform_id=1")
# if r.status_code == 404:
# raise NotFoundError("The specified user has never played Rocket League")
# elif r.status_code != 200:
# raise RequestError("Rocket League Stats returned {r.status_code}")
# new_record = RocketLeague(steam_id=steam_id)
# new_record.update(data=r.json())
# return new_record
def update(self, data=None):
if data is None:
r = requests.get(f"https://api.rocketleaguestats.com/v1/player?apikey={config['Rocket League']['rlstats_api_key']}&unique_id={self.steam_id}&platform_id=1")
if r.status_code != 200:
raise RequestError(f"Rocket League Stats returned {r.status_code}")
data = r.json()
# Get current season
current_season = 0
for season in data["rankedSeasons"]:
if int(season) > current_season:
current_season = int(season)
if current_season == 0:
return
self.season = current_season
current_season = str(current_season)
# Get wins
self.wins = data["stats"]["wins"]
# Get ranked data
# Single 1v1
if "10" in data["rankedSeasons"][current_season]:
self.single_mmr = data["rankedSeasons"][current_season]["10"]["rankPoints"]
if data["rankedSeasons"][current_season]["10"]["matchesPlayed"] >= 10:
self.single_rank = data["rankedSeasons"][current_season]["10"]["tier"]
self.single_div = data["rankedSeasons"][current_season]["10"]["division"]
else:
self.single_rank = None
self.single_div = None
# Doubles 2v2
if "11" in data["rankedSeasons"][current_season]:
self.doubles_mmr = data["rankedSeasons"][current_season]["11"]["rankPoints"]
if data["rankedSeasons"][current_season]["11"]["matchesPlayed"] >= 10:
self.doubles_rank = data["rankedSeasons"][current_season]["11"]["tier"]
self.doubles_div = data["rankedSeasons"][current_season]["11"]["division"]
else:
self.doubles_rank = None
self.doubles_div = None
# Standard 3v3
if "13" in data["rankedSeasons"][current_season]:
self.standard_mmr = data["rankedSeasons"][current_season]["13"]["rankPoints"]
if data["rankedSeasons"][current_season]["13"]["matchesPlayed"] >= 10:
self.standard_rank = data["rankedSeasons"][current_season]["13"]["tier"]
self.standard_div = data["rankedSeasons"][current_season]["13"]["division"]
else:
self.standard_rank = None
self.standard_div = None
# Solo Standard 3v3
if "12" in data["rankedSeasons"][current_season]:
self.solo_std_mmr = data["rankedSeasons"][current_season]["12"]["rankPoints"]
if data["rankedSeasons"][current_season]["12"]["matchesPlayed"] >= 10:
self.solo_std_rank = data["rankedSeasons"][current_season]["12"]["tier"]
self.solo_std_div = data["rankedSeasons"][current_season]["12"]["division"]
else:
self.solo_std_rank = None
self.solo_std_div = None
# def update(self, data=None):
# if data is None:
# r = requests.get(f"https://api.rocketleaguestats.com/v1/player?apikey={config['Rocket League']['rlstats_api_key']}&unique_id={self.steam_id}&platform_id=1")
# if r.status_code != 200:
# raise RequestError(f"Rocket League Stats returned {r.status_code}")
# data = r.json()
# # Get current season
# current_season = 0
# for season in data["rankedSeasons"]:
# if int(season) > current_season:
# current_season = int(season)
# if current_season == 0:
# return
# self.season = current_season
# current_season = str(current_season)
# # Get wins
# self.wins = data["stats"]["wins"]
# # Get ranked data
# # Single 1v1
# if "10" in data["rankedSeasons"][current_season]:
# self.single_mmr = data["rankedSeasons"][current_season]["10"]["rankPoints"]
# if data["rankedSeasons"][current_season]["10"]["matchesPlayed"] >= 10:
# self.single_rank = data["rankedSeasons"][current_season]["10"]["tier"]
# self.single_div = data["rankedSeasons"][current_season]["10"]["division"]
# else:
# self.single_rank = None
# self.single_div = None
# # Doubles 2v2
# if "11" in data["rankedSeasons"][current_season]:
# self.doubles_mmr = data["rankedSeasons"][current_season]["11"]["rankPoints"]
# if data["rankedSeasons"][current_season]["11"]["matchesPlayed"] >= 10:
# self.doubles_rank = data["rankedSeasons"][current_season]["11"]["tier"]
# self.doubles_div = data["rankedSeasons"][current_season]["11"]["division"]
# else:
# self.doubles_rank = None
# self.doubles_div = None
# # Standard 3v3
# if "13" in data["rankedSeasons"][current_season]:
# self.standard_mmr = data["rankedSeasons"][current_season]["13"]["rankPoints"]
# if data["rankedSeasons"][current_season]["13"]["matchesPlayed"] >= 10:
# self.standard_rank = data["rankedSeasons"][current_season]["13"]["tier"]
# self.standard_div = data["rankedSeasons"][current_season]["13"]["division"]
# else:
# self.standard_rank = None
# self.standard_div = None
# # Solo Standard 3v3
# if "12" in data["rankedSeasons"][current_season]:
# self.solo_std_mmr = data["rankedSeasons"][current_season]["12"]["rankPoints"]
# if data["rankedSeasons"][current_season]["12"]["matchesPlayed"] >= 10:
# self.solo_std_rank = data["rankedSeasons"][current_season]["12"]["tier"]
# self.solo_std_div = data["rankedSeasons"][current_season]["12"]["division"]
# else:
# self.solo_std_rank = None
# self.solo_std_div = None
def solo_rank_image(self):
if self.single_rank is None:

View file

@ -67,7 +67,7 @@
<li><a href="/game/discord">Discord</a></li>
<li><a href="/game/steam">Steam</a></li>
<li><a href="/game/dota">Dota 2</a></li>
<li><a href="/game/rl">Rocket League</a></li>
<!--li><a href="/game/rl">Rocket League</a></li-->
<li><a href="/game/lol">League of Legends</a></li>
<li><a href="/game/ow">Overwatch</a></li>
<li><a href="/game/osu">osu!</a></li>

View file

@ -56,11 +56,11 @@
{% include "minis/dota.html" %}
{% endwith %}
{% endif %}
{% if rl %}
{# if rl %}
{% with record = rl %}
{% include "minis/rl.html" %}
{% endwith %}
{% endif %}
{% endif #}
{% if osu %}
{% with record = osu %}
{% include "minis/osu.html" %}

View file

@ -24,21 +24,21 @@ try:
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)
# 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():

View file

@ -77,7 +77,7 @@ def page_profile(name: str):
css = db_session.query(db.ProfileData).filter_by(royal=user).one_or_none()
steam = db_session.query(db.Steam).filter_by(royal=user).one_or_none()
osu = db_session.query(db.Osu).filter_by(royal=user).one_or_none()
rl = db_session.query(db.RocketLeague).join(db.Steam).filter_by(royal=user).one_or_none()
# rl = db_session.query(db.RocketLeague).join(db.Steam).filter_by(royal=user).one_or_none()
dota = db_session.query(db.Dota).join(db.Steam).filter_by(royal=user).one_or_none()
lol = db_session.query(db.LeagueOfLegends).filter_by(royal=user).one_or_none()
ow = db_session.query(db.Overwatch).filter_by(royal=user).one_or_none()
@ -86,7 +86,7 @@ def page_profile(name: str):
db_session.close()
converted_bio = Markup(markdown2.markdown(css.bio.replace("<", "&lt;"),
extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"]))
return render_template("profile.html", ryg=user, css=css, osu=osu, rl=rl, dota=dota, lol=lol, steam=steam, ow=ow,
return render_template("profile.html", ryg=user, css=css, osu=osu, dota=dota, lol=lol, steam=steam, ow=ow,
tg=tg, discord=discord, config=config, bio=converted_bio)