Skip to content

Instantly share code, notes, and snippets.

@kobus-v-schoor
Created August 24, 2020 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobus-v-schoor/3c86dcff2a45cb9959ac35b84196f763 to your computer and use it in GitHub Desktop.
Save kobus-v-schoor/3c86dcff2a45cb9959ac35b84196f763 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
import requests
import subprocess
import time
from datetime import datetime, timedelta
# put your AppServiceAuthSession cookie in a file named cookie
with open('cookie', 'r') as f:
cookies = {'AppServiceAuthSession': f.read().strip()}
url = 'https://entelect-challenge-functions.azurewebsites.net/api/ListTournamentMatches/vrrrpa-wanna-dice-chaana'
start = datetime.now()
print("ignoring everything before", start)
# server time is in utc
start -= timedelta(hours=2)
# holds the matches that we've already seen
done = []
# converts the times to datetime objects
def stodt(s):
return datetime.strptime(s[:19], "%Y-%m-%dT%H:%M:%S")
while True:
matches = requests.get(url, cookies=cookies)
if not matches.text:
print("unable to get a response, maybe update your cookie?")
break
matches = matches.json()
# tally up played matches
wins = 0
total = 0
for match in matches:
if not match['isDraw']:
if match['isWinner']:
wins += 1
total += 1
# calculate win rate
wr = round(100 * wins / total, 2)
print(f"{datetime.now()}: {total} matches found")
for match in matches:
# match hasn't been played
if match['isDraw']:
continue
# check if we won
won = match['isWinner']
# match played before script start time
if stodt(match['startTime']) < start:
continue
# already did this one
if match['matchId'] in done:
continue
user = match['opponentUsername']
# notification message
msg = (("Won" if won else "Lost") + f" against {user} " +
f"({wins}/{total} {wr}%)")
print(msg)
# notify
# insert your notification method here
# subprocess.run(["notify-send", msg])
done.append(match['matchId'])
# wait 10 minutes
time.sleep(10 * 60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment