-
Notifications
You must be signed in to change notification settings - Fork 1
/
crickscorebot.py
52 lines (43 loc) · 1.8 KB
/
crickscorebot.py
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
43
44
45
46
47
48
49
50
51
52
import telegram_send
import requests
import json
import time
import telegram
token = "ADD TOKEN"
bot = telegram.Bot(token)
scorelist = [0]*100
prevdata = ""
while True:
count = 0
response = requests.get('https://hs-consumer-api.espncricinfo.com/v1/pages/matches/live?')
time.sleep(5)
data = json.loads(response.text)
if prevdata != data:
prevdata = data
for liveInning in data['content']['matches']:
if liveInning['liveInning'] != None:
msg = ""
msg = msg + "### "+ liveInning['slug'] +" ###" + "\n"
msg = msg + liveInning['state'] + "\n"
msg = msg + liveInning['statusText'] + "\n"
flag = False
for isLive in liveInning['teams']:
if isLive['isLive'] == False:
if isLive['score'] == None:
msg = msg + "Bowling..." + "\n"
else:
msg = msg + isLive['team']['name']+" scored: "+isLive['score'] + "\n"
if isLive['isLive'] == True:
if scorelist[count] == 0:
scorelist.insert(count, isLive['score'])
flag = True
elif scorelist[count] != isLive['score']:
flag = True
scorelist[count] = isLive['score']
else:
flag = False
msg = msg + isLive['team']['name']+" current score: "+isLive['score'] + "\n"
msg = msg + "Score Info: "+isLive['scoreInfo'] + "\n"
if flag == True:
output = bot.send_message(chat_id="ADD CHAT ID", text=msg)
count = count+1