-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.py
71 lines (56 loc) · 2.18 KB
/
sample.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import requests, argparse
from lxml.html import fromstring
from win10toast import ToastNotifier
import time
from bs4 import BeautifulSoup
parser = argparse.ArgumentParser()
parser.add_argument(
'--url',
'-url',
default='https://www.espncricinfo.com/series/8050/game/1203608/bengal-vs-odisha-2nd-quarter-final-ranji-trophy-2019-20' ,
help='url from espncricinfo.com of match')
args = parser.parse_args()
left = '('
right = ' ov'
PreviousRuns = 0;
PreviousWickets = 0;
previous_overs = 0
commentary = ''
score = ''
overs = ''
ignore_first = True
def GetScore():
page = requests.Session().get(args.url)
score = fromstring(page.content).findtext('.//title').split('- Live')[0]
soup = BeautifulSoup(page.text,'lxml')
commentary = soup.find("div", {"class": "commentary-item"})
print(commentary)
description = commentary.find("div", {"class": "description"})
return score, description.text.strip() if description is not None else ''
def ShowNotification(title, score, delay =5):
toaster = ToastNotifier()
toaster.show_toast(title, score, icon_path=None, duration=delay, threaded=True)
while toaster.notification_active(): time.sleep(0.1)
def printSummary():
print('\n', commentary + '\n' +score + ' ' + str(overs))
#ShowNotification('Test !!!',score+ ' ' + str(overs))
while (True):
time.sleep(3)
summary, commentary = GetScore()
score = summary.split(' ')[1]
Runs = score.split('/')[0]
Wickets = score.split('/')[1]
overs = float(summary[summary.index(left)+len(left):summary.index(right)])
if (int(Runs)-int(PreviousRuns)) == 4:
ShowNotification('Four !!!',commentary + '\n' +score)
elif (int(Runs)-int(PreviousRuns)) == 6:
ShowNotification('Six !!!',score)
if (int(Runs)-int(PreviousRuns)) >= 1 or overs > previous_overs:
printSummary()
if int(Wickets) - int(PreviousWickets) == 1 and not ignore_first:
ShowNotification('Wicket!!!',commentary + '\n' + score)
printSummary()
ignore_first = False
PreviousRuns = Runs
PreviousWickets = Wickets
previous_overs = overs