Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added time until next match, when there are no live matches. #99

Merged
merged 6 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"None - next in {str(days)}d" if days else f'None - next in {hours}h {minutes}m'
except:
return ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it to "None" to keep it consistent.



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 @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would ideally like to see the addition of a timeout between each check of getTimeUntilNextMatch but it is not necessary. It would mostly be for efficiency purposes, so you aren't making multiple unnecessary requests per thread.

Copy link
Owner

@LeagueOfPoro LeagueOfPoro Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should actually refactor the whole program and create a new thread that would handle common tasks. Like get live, schedule etc.

Those actions do not require auth.

self.stats.update(self.account, len(newDrops), liveMatchesMsg)
if self.config.connectorDrops:
self.__notifyConnectorDrops(newDrops)
Expand Down