Skip to content

Commit

Permalink
feat: Added time until next match, when there are no live matches. (#99)
Browse files Browse the repository at this point in the history
* Added time until next match, when there are no live matches.

* 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.

* Fixes

* Catch StatusCodeAssertException

* Exclude matches in progress

---------

Co-authored-by: League of Poro <95635582+LeagueOfPoro@users.noreply.github.com>
  • Loading branch information
wiflow and LeagueOfPoro authored Feb 10, 2023
1 parent 97a8682 commit 0719b37
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/Browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,42 @@ 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"}
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, statusCode, url)
resJson = res.json()
res.close()
events = resJson["data"]["schedule"]["events"]
for event in events:
try:
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:
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"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"

def getLiveMatches(self):
"""
Retrieve data about currently live matches and store them.
Expand Down
4 changes: 2 additions & 2 deletions src/FarmThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def run(self):
else:
leagueName = str(m.league)
liveMatchesStatus.append(leagueName)
self.log.debug(f"Live matches: {', '.join(liveMatchesStatus)}")
self.log.debug(f"Live matches: {', '.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)
Expand Down

0 comments on commit 0719b37

Please sign in to comment.