From 0ee007a90675fa853ca74083bc0710a8f0018c59 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 16 Aug 2018 16:25:05 +0200 Subject: [PATCH] Disable Rocket League after the API shutdown --- db.py | 134 ++++++++++++++++++++--------------------- templates/main.html | 2 +- templates/profile.html | 4 +- update.py | 30 ++++----- webserver.py | 4 +- 5 files changed, 87 insertions(+), 87 deletions(-) diff --git a/db.py b/db.py index bf09215a..65d356a6 100644 --- a/db.py +++ b/db.py @@ -198,74 +198,74 @@ class RocketLeague(Base): def __repr__(self): return f"" - @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: diff --git a/templates/main.html b/templates/main.html index 7da05b20..ffbf0209 100644 --- a/templates/main.html +++ b/templates/main.html @@ -67,7 +67,7 @@
  • Discord
  • Steam
  • Dota 2
  • -
  • Rocket League
  • +
  • League of Legends
  • Overwatch
  • osu!
  • diff --git a/templates/profile.html b/templates/profile.html index 5ad5f64f..b7bd81a4 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -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" %} diff --git a/update.py b/update.py index 232e37a8..030a9d1e 100644 --- a/update.py +++ b/update.py @@ -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(): diff --git a/webserver.py b/webserver.py index d7bd5a30..08e3e2ee 100644 --- a/webserver.py +++ b/webserver.py @@ -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("<", "<"), 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)