1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +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): def __repr__(self):
return f"<RocketLeague {self.steam_id}>" return f"<RocketLeague {self.steam_id}>"
@staticmethod # @staticmethod
def create(session: Session, steam_id: str): # def create(session: Session, steam_id: str):
rl = session.query(RocketLeague).get(steam_id) # rl = session.query(RocketLeague).get(steam_id)
if rl is not None: # if rl is not None:
raise AlreadyExistingError(repr(rl)) # 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") # 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: # if r.status_code == 404:
raise NotFoundError("The specified user has never played Rocket League") # raise NotFoundError("The specified user has never played Rocket League")
elif r.status_code != 200: # elif r.status_code != 200:
raise RequestError("Rocket League Stats returned {r.status_code}") # raise RequestError("Rocket League Stats returned {r.status_code}")
new_record = RocketLeague(steam_id=steam_id) # new_record = RocketLeague(steam_id=steam_id)
new_record.update(data=r.json()) # new_record.update(data=r.json())
return new_record # return new_record
def update(self, data=None): # def update(self, data=None):
if data is 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") # 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: # if r.status_code != 200:
raise RequestError(f"Rocket League Stats returned {r.status_code}") # raise RequestError(f"Rocket League Stats returned {r.status_code}")
data = r.json() # data = r.json()
# Get current season # # Get current season
current_season = 0 # current_season = 0
for season in data["rankedSeasons"]: # for season in data["rankedSeasons"]:
if int(season) > current_season: # if int(season) > current_season:
current_season = int(season) # current_season = int(season)
if current_season == 0: # if current_season == 0:
return # return
self.season = current_season # self.season = current_season
current_season = str(current_season) # current_season = str(current_season)
# Get wins # # Get wins
self.wins = data["stats"]["wins"] # self.wins = data["stats"]["wins"]
# Get ranked data # # Get ranked data
# Single 1v1 # # Single 1v1
if "10" in data["rankedSeasons"][current_season]: # if "10" in data["rankedSeasons"][current_season]:
self.single_mmr = data["rankedSeasons"][current_season]["10"]["rankPoints"] # self.single_mmr = data["rankedSeasons"][current_season]["10"]["rankPoints"]
if data["rankedSeasons"][current_season]["10"]["matchesPlayed"] >= 10: # if data["rankedSeasons"][current_season]["10"]["matchesPlayed"] >= 10:
self.single_rank = data["rankedSeasons"][current_season]["10"]["tier"] # self.single_rank = data["rankedSeasons"][current_season]["10"]["tier"]
self.single_div = data["rankedSeasons"][current_season]["10"]["division"] # self.single_div = data["rankedSeasons"][current_season]["10"]["division"]
else: # else:
self.single_rank = None # self.single_rank = None
self.single_div = None # self.single_div = None
# Doubles 2v2 # # Doubles 2v2
if "11" in data["rankedSeasons"][current_season]: # if "11" in data["rankedSeasons"][current_season]:
self.doubles_mmr = data["rankedSeasons"][current_season]["11"]["rankPoints"] # self.doubles_mmr = data["rankedSeasons"][current_season]["11"]["rankPoints"]
if data["rankedSeasons"][current_season]["11"]["matchesPlayed"] >= 10: # if data["rankedSeasons"][current_season]["11"]["matchesPlayed"] >= 10:
self.doubles_rank = data["rankedSeasons"][current_season]["11"]["tier"] # self.doubles_rank = data["rankedSeasons"][current_season]["11"]["tier"]
self.doubles_div = data["rankedSeasons"][current_season]["11"]["division"] # self.doubles_div = data["rankedSeasons"][current_season]["11"]["division"]
else: # else:
self.doubles_rank = None # self.doubles_rank = None
self.doubles_div = None # self.doubles_div = None
# Standard 3v3 # # Standard 3v3
if "13" in data["rankedSeasons"][current_season]: # if "13" in data["rankedSeasons"][current_season]:
self.standard_mmr = data["rankedSeasons"][current_season]["13"]["rankPoints"] # self.standard_mmr = data["rankedSeasons"][current_season]["13"]["rankPoints"]
if data["rankedSeasons"][current_season]["13"]["matchesPlayed"] >= 10: # if data["rankedSeasons"][current_season]["13"]["matchesPlayed"] >= 10:
self.standard_rank = data["rankedSeasons"][current_season]["13"]["tier"] # self.standard_rank = data["rankedSeasons"][current_season]["13"]["tier"]
self.standard_div = data["rankedSeasons"][current_season]["13"]["division"] # self.standard_div = data["rankedSeasons"][current_season]["13"]["division"]
else: # else:
self.standard_rank = None # self.standard_rank = None
self.standard_div = None # self.standard_div = None
# Solo Standard 3v3 # # Solo Standard 3v3
if "12" in data["rankedSeasons"][current_season]: # if "12" in data["rankedSeasons"][current_season]:
self.solo_std_mmr = data["rankedSeasons"][current_season]["12"]["rankPoints"] # self.solo_std_mmr = data["rankedSeasons"][current_season]["12"]["rankPoints"]
if data["rankedSeasons"][current_season]["12"]["matchesPlayed"] >= 10: # if data["rankedSeasons"][current_season]["12"]["matchesPlayed"] >= 10:
self.solo_std_rank = data["rankedSeasons"][current_season]["12"]["tier"] # self.solo_std_rank = data["rankedSeasons"][current_season]["12"]["tier"]
self.solo_std_div = data["rankedSeasons"][current_season]["12"]["division"] # self.solo_std_div = data["rankedSeasons"][current_season]["12"]["division"]
else: # else:
self.solo_std_rank = None # self.solo_std_rank = None
self.solo_std_div = None # self.solo_std_div = None
def solo_rank_image(self): def solo_rank_image(self):
if self.single_rank is None: if self.single_rank is None:

View file

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

View file

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

View file

@ -24,21 +24,21 @@ try:
sleep_time = 1 - time.clock() + t sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0) time.sleep(sleep_time if sleep_time > 0 else 0)
# Update Rocket League # Update Rocket League
print("ROCKET LEAGUE") # print("ROCKET LEAGUE")
for user in session.query(db.RocketLeague).all(): # for user in session.query(db.RocketLeague).all():
t = time.clock() # t = time.clock()
print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True) # print(f"Updating {user.steam.royal.username}", end="\t\t", flush=True)
try: # try:
user.update() # user.update()
except errors.RequestError: # except errors.RequestError:
print("Request Error") # print("Request Error")
except errors.NotFoundError: # except errors.NotFoundError:
print("Not Found Error (?)") # print("Not Found Error (?)")
else: # else:
print("OK") # print("OK")
finally: # finally:
sleep_time = 1 - time.clock() + t # sleep_time = 1 - time.clock() + t
time.sleep(sleep_time if sleep_time > 0 else 0) # time.sleep(sleep_time if sleep_time > 0 else 0)
# Update Dota 2 # Update Dota 2
print("DOTA 2") print("DOTA 2")
for user in session.query(db.Dota).all(): 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() 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() 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() 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() 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() 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() 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() db_session.close()
converted_bio = Markup(markdown2.markdown(css.bio.replace("<", "&lt;"), converted_bio = Markup(markdown2.markdown(css.bio.replace("<", "&lt;"),
extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"])) 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) tg=tg, discord=discord, config=config, bio=converted_bio)