-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgoalnotify.py
More file actions
55 lines (45 loc) · 1.48 KB
/
goalnotify.py
File metadata and controls
55 lines (45 loc) · 1.48 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
43
44
45
46
47
48
49
50
51
52
53
54
55
import pynotify
import urllib2
from bs4 import BeautifulSoup
import urllib2
import os
SNSWITCH=raw_input('Do you want sound notifications('+'yes/no): ')
if SNSWITCH=='yes':
time=0.5
elif SNSWITCH=='y':
time=0.5
else:
time=0.01
URL=raw_input("Paste the URL of the match: ")
try:
response=urllib2.urlopen(URL)
html=response.read()
except urllib2.HTTPError, e:
print 'HTTP Error, '+e.code
quit()
except urllib2.URLError, e:
print 'URL Error '+e.args
quit()
soup=BeautifulSoup(html)
HomeTeam=soup.find('div',attrs={'class':'home'})
HomeTeamName=HomeTeam.find('h2').text
AwayTeam=soup.find('div',attrs={'class':'away'})
AwayTeamName=AwayTeam.find('h2').text
Initial_Home_Score='-1'
Initial_Away_Score='-1'
title = str(HomeTeamName)+' Vs '+str(AwayTeamName)
icon = "/usr/share/icons/Humanity/emblems/32/emblem-ohno.png"
while (True):
response=urllib2.urlopen(URL)
soup=BeautifulSoup(response)
Home_Score=soup.find('div',attrs={'class':'home-score'}).text
Away_Score=soup.find('div',attrs={'class':'away-score'}).text
if(int(Home_Score)!=int(Initial_Home_Score)) or(int(Away_Score) != int(Initial_Away_Score)):
text = str(Home_Score )+' - '+str(Away_Score)
pynotify.init('Score Updates')
notification = pynotify.Notification(title, text, icon)
notification.set_urgency(pynotify.URGENCY_NORMAL)
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % (time, 3000))
notification.show()
Initial_Away_Score=Away_Score
Initial_Home_Score=Home_Score