-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification.py
More file actions
62 lines (50 loc) · 2.13 KB
/
notification.py
File metadata and controls
62 lines (50 loc) · 2.13 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
56
57
58
59
60
61
62
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#This class takes care of notifications of favourite streamers
#coming online. It checks every five minutes whether or not
#a streamer who was previously offline has come online
import pygtk
import pynotify
import sys,favourites,streamer,gtk
class Main():
def __init__(self):
self.startFav = []
self.fav = favourites.Favourites()
#Sets the online tag of each favourite
self.fav.setOnlineStatus()
#Load all of the favourites at start time into here
self.startFav = self.fav.loadFavourites()
#Check if streamers come online every 5 minutes
gtk.timeout_add(60*1000, self.myTimer)
def myTimer(self):
self.currentFav = []
self.cFav = favourites.Favourites()
self.cFav.setOnlineStatus()
#Load all of the current fav's(Every 5 mins)
self.currentFav = self.cFav.loadFavourites()
#Most recent favourites list
for x in self.currentFav:
#Previous list
for z in self.startFav:
#Same streamer in both
if x.getName() == z.getName():
#Currently online
if x.getStatus() == "online":
#Stream has gone from offline to online
if z.getStatus() == "offline":
if pynotify.init("Basics"):
#Notification of stream coming online!
a = z.getName()
print a + " is now online!"
n = pynotify.Notification(a,"is now online")
n.show()
else:
print "Failed to send notification"
sys.exit(1)
#Put the most recent list into the old one, so people
#who have gone offline since the program started will
#trigger a notification if the come back online
self.startFav = self.currentFav
return True
if __name__ == '__main__':
sys.exit()