-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
72 lines (69 loc) · 2.63 KB
/
main.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
72
#Parser for html
from lxml import html
#For Notifications on your desktop
from gi.repository import Notify
import requests
import time
#download the cricbuzz library and do pip install cricbuzz
from cricbuzz import *
#The Twilio API
from twilio.rest import TwilioRestClient
#Enter your Twilio account SID and Auth Token
accountSid = ""
authToken = ""
#Calling the Cricbuzz Parser from cricbuzz.py
cric = CricbuzzParser()
#Calling the Twilio API
twilioClient = TwilioRestClient(accountSid, authToken)
#Enter your phone number and that of the receiver
myTwilioNumber = "+999"
destCellPhone = "+999"
#Special parser for test matches
def test(**match):
#Takes a dict as input
if match['State']=='Result':
#Generates the message
s = match['Match']+ " Test Match at "+match['Venue']+"\n"+match['Status']
return s
def func():
#Gets the XML file from Cricbuzz
match = cric.getXml()
details = cric.handleMatches(match)
#Parses it and filters the None Type Elements
details = filter(None,details)
message = ''
count=0
for i in details:
#Traverses the list
if i['Match Format']=='TEST':
#If it is a test match, sends it to the special function
count+=1
#generates the message from test()
message = message+"\n"+test(**i)
elif 'Match State' in i:
if i['Match State'] == 'inprogress' or i['Match State']=='rain':
#If the match is in progress
count+=1
#Generate an appropriate message when a match is in progress
message = message+"\n\n"+ i['Team']+ " "+ i['Match Format'] + ' Match at ' + i['Venue']+ "\n" +i['Batting team'] + ' ' + i['Batting Team Runs'] +'/'+i['Batting Team Wickets'] + ' Overs: ' + i['Batting Team Overs'] + "\n" + i['Match Status']
elif (i['Match State'] == 'complete' or i['Match State'] == 'result' or i['Match State'] == 'Result'):
#Displays the result of already complete matches
message =message+"\n\n"+i['Team']+" "+ i['Match Format'] + ' Match at ' + i['Venue']+"\n"+i['Match Status']
count+=1
if count == 0 :
#If no match is in progress, or if there is no other data to show
message='No Match Available'
Notify.init("Live Scores")
#Initialise Notify
Notify.Notification.new("Score Update: ",message).show()
#Displaying the notification
myMessage = twilioClient.messages.create(body = "Score Update:" + message, from_=myTwilioNumber, to=destCellPhone)
#Sending a text message via Twilio
if not message == 'No Match Available':
time.sleep(60)
#Defines a time interval of 60 seconds
else:
#If no match is available, it quits the script
exit()
while True:
func()