From 095ba6caa2cf9c9f424575d180efb35ba5399b78 Mon Sep 17 00:00:00 2001 From: Nicklas Date: Wed, 8 Feb 2023 22:17:37 +0100 Subject: [PATCH 1/5] Added time until next match, when there are no live matches. --- src/Browser.py | 29 +++++++++++++++++++++++++++++ src/FarmThread.py | 4 ++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Browser.py b/src/Browser.py index 36596e5..6e40ca0 100644 --- a/src/Browser.py +++ b/src/Browser.py @@ -131,6 +131,35 @@ def maintainSession(self): self.log.debug("Refreshing session.") self.refreshSession() + def getTimeUntilNextMatch(self): + """ + Retrieve data about currently live matches and store them. + """ + headers = {"Origin": "https://lolesports.com", "Referrer": "https://lolesports.com", + "x-api-key": "0TvQnueqKa5mxJntVWt0w4LpLfEkrV1Ta8rQBb9Z"} + res = self.client.get( + "https://esports-api.lolesports.com/persisted/gw/getSchedule?hl=en-GB", headers=headers) + if res.status_code != 200: + raise StatusCodeAssertException(200, res.status_code, res.request.url) + resJson = res.json() + try: + events = resJson["data"]["schedule"]["events"] + for event in events: + try: + startTime = datetime.strptime(event["startTime"], '%Y-%m-%dT%H:%M:%SZ') #Some matches aparrently don't have a starttime + except: + continue + if datetime.now() < startTime: + timeUntil = startTime - datetime.now() + total_seconds = int(timeUntil.total_seconds() + 3600) + days, remainder = divmod(total_seconds, 86400) + hours, remainder = divmod(remainder, 3600) + minutes, seconds = divmod(remainder, 60) + return f'{days}d {hours}h {minutes}m' + except: + return "" + + def getLiveMatches(self): """ Retrieve data about currently live matches and store them. diff --git a/src/FarmThread.py b/src/FarmThread.py index e670a37..b88fa32 100644 --- a/src/FarmThread.py +++ b/src/FarmThread.py @@ -44,12 +44,12 @@ def run(self): liveMatchesStatus = [] for m in self.browser.liveMatches.values(): liveMatchesStatus.append(f"{m.league}") - self.log.debug(f"{', '.join(liveMatchesStatus)}") + self.log.debug(f"{', '.join(liveMatchesStatus)}") liveMatchesMsg = f"{', '.join(liveMatchesStatus)}" newDrops = self.browser.checkNewDrops(self.stats.getLastDropCheck(self.account)) self.stats.updateLastDropCheck(self.account, int(datetime.now().timestamp()*1e3)) else: - liveMatchesMsg = "None" + liveMatchesMsg = self.browser.getTimeUntilNextMatch() self.stats.update(self.account, len(newDrops), liveMatchesMsg) if self.config.connectorDrops: self.__notifyConnectorDrops(newDrops) From 7fe3ea40af8224a1eedda6c71ba21fbed1edf86c Mon Sep 17 00:00:00 2001 From: Nicklas Date: Thu, 9 Feb 2023 14:48:00 +0100 Subject: [PATCH 2/5] Only displaying days, when there is days, and if there are no days, display hours and minutes. Also added "None - " in front of time until next match, as requested. --- src/Browser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Browser.py b/src/Browser.py index 6e40ca0..644a7af 100644 --- a/src/Browser.py +++ b/src/Browser.py @@ -155,7 +155,7 @@ def getTimeUntilNextMatch(self): days, remainder = divmod(total_seconds, 86400) hours, remainder = divmod(remainder, 3600) minutes, seconds = divmod(remainder, 60) - return f'{days}d {hours}h {minutes}m' + return f"None - next in {str(days)}d" if days else f'None - next in {hours}h {minutes}m' except: return "" From 708af71e951964b001d3e6754b9e50b69914fda1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicklas=20S=C3=B8rensen?= Date: Fri, 10 Feb 2023 08:54:52 +0100 Subject: [PATCH 3/5] Fixes --- src/Browser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Browser.py b/src/Browser.py index 644a7af..25e4dd8 100644 --- a/src/Browser.py +++ b/src/Browser.py @@ -139,8 +139,6 @@ def getTimeUntilNextMatch(self): "x-api-key": "0TvQnueqKa5mxJntVWt0w4LpLfEkrV1Ta8rQBb9Z"} res = self.client.get( "https://esports-api.lolesports.com/persisted/gw/getSchedule?hl=en-GB", headers=headers) - if res.status_code != 200: - raise StatusCodeAssertException(200, res.status_code, res.request.url) resJson = res.json() try: events = resJson["data"]["schedule"]["events"] @@ -157,7 +155,9 @@ def getTimeUntilNextMatch(self): minutes, seconds = divmod(remainder, 60) return f"None - next in {str(days)}d" if days else f'None - next in {hours}h {minutes}m' except: - return "" + return "None" + if res.status_code != 200: + raise StatusCodeAssertException(200, res.status_code, res.request.url) def getLiveMatches(self): From 1290fddee3b5b7e9d109feac9c2096cb3444d41c Mon Sep 17 00:00:00 2001 From: League of Poro <95635582+LeagueOfPoro@users.noreply.github.com> Date: Fri, 10 Feb 2023 09:34:27 +0100 Subject: [PATCH 4/5] Catch StatusCodeAssertException --- src/Browser.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Browser.py b/src/Browser.py index 25e4dd8..ce619d0 100644 --- a/src/Browser.py +++ b/src/Browser.py @@ -137,10 +137,16 @@ def getTimeUntilNextMatch(self): """ headers = {"Origin": "https://lolesports.com", "Referrer": "https://lolesports.com", "x-api-key": "0TvQnueqKa5mxJntVWt0w4LpLfEkrV1Ta8rQBb9Z"} - res = self.client.get( - "https://esports-api.lolesports.com/persisted/gw/getSchedule?hl=en-GB", headers=headers) - resJson = res.json() try: + res = self.client.get( + "https://esports-api.lolesports.com/persisted/gw/getSchedule?hl=en-GB", headers=headers) + if res.status_code != 200: + statusCode = res.status_code + url = res.request.url + res.close() + raise StatusCodeAssertException(200, res.status_code, res.request.url) + resJson = res.json() + res.close() events = resJson["data"]["schedule"]["events"] for event in events: try: @@ -154,11 +160,11 @@ def getTimeUntilNextMatch(self): hours, remainder = divmod(remainder, 3600) minutes, seconds = divmod(remainder, 60) return f"None - next in {str(days)}d" if days else f'None - next in {hours}h {minutes}m' + except StatusCodeAssertException as ex: + self.log.error(ex) + return "None" except: return "None" - if res.status_code != 200: - raise StatusCodeAssertException(200, res.status_code, res.request.url) - def getLiveMatches(self): """ From 24e048b96816146686858c96e028b293dd255c31 Mon Sep 17 00:00:00 2001 From: League of Poro <95635582+LeagueOfPoro@users.noreply.github.com> Date: Fri, 10 Feb 2023 09:49:14 +0100 Subject: [PATCH 5/5] Exclude matches in progress --- src/Browser.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Browser.py b/src/Browser.py index ce619d0..75d3aac 100644 --- a/src/Browser.py +++ b/src/Browser.py @@ -144,13 +144,14 @@ def getTimeUntilNextMatch(self): statusCode = res.status_code url = res.request.url res.close() - raise StatusCodeAssertException(200, res.status_code, res.request.url) + raise StatusCodeAssertException(200, statusCode, url) resJson = res.json() res.close() events = resJson["data"]["schedule"]["events"] for event in events: try: - startTime = datetime.strptime(event["startTime"], '%Y-%m-%dT%H:%M:%SZ') #Some matches aparrently don't have a starttime + if "inProgress" != event["state"]: + startTime = datetime.strptime(event["startTime"], '%Y-%m-%dT%H:%M:%SZ') #Some matches aparrently don't have a starttime except: continue if datetime.now() < startTime: