-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcricket_score.py
More file actions
42 lines (34 loc) · 1.16 KB
/
cricket_score.py
File metadata and controls
42 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import requests, json, time
from win10toast import ToastNotifier
def notify(score):
# Function for Windows toast desktop notification
toaster = ToastNotifier()
toaster.show_toast(score, "Get! Set! GO!", duration=5)
# Score set to empty initially.
score = ''
url = 'http://cricscore-api.appspot.com/csa'
def get_match_names():
response = requests.get(url)
data = json.loads(response.content.decode('utf-8'))
return data
def get_desired_match(data):
m = {}
print("Match List.")
print("===========")
for k, v in enumerate(data):
# v = dict(v)
m[k] = v["id"]
print("%s. %s v/s %s" %(k+1, v["t1"], v["t2"]))
i = int(input("Pick One [1-%s]: " %(len(data))))
return m[i-1]
def get_score(match_id):
while True:
response = requests.get('%s?id=%s' % (url, match_id) )
data = json.loads(response.content.decode('utf-8'))
data = json.loads(response.content.decode('utf-8'))
new_score = data[0]['de']
notify(new_score)
time.sleep(30)
match_names = get_match_names()
match_id = get_desired_match(match_names)
get_score(match_id)