-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfs-notify.py
executable file
·67 lines (49 loc) · 1.78 KB
/
fs-notify.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
#!/usr/bin/env python
import ConfigHandler
import foursquare
import pynotify
import urllib
import gtk
import os
from gtk import gdk
class FoursquareNotifier():
_cfgHandler = None
notifier = None
poll_timer = None
def __init__(self):
self._cfgHandler = ConfigHandler.ConfigHandler()
if not pynotify.init("Foursquare Notifier"):
print "Unable to initialise notifier"
exit(1)
print self._cfgHandler.options
# Set the process timeour for checking for new checkins
self.poll_timer = gtk.timeout_add(self._cfgHandler.options["poll_timeout"], self.poll_for_checkins )
def poll_for_checkins(self):
"""
Get the latest set of checkins from the foursquare api
"""
fapi = foursquare.Api()
checkins = fapi.get_checkins(self._cfgHandler.options["foursquare_username"], self._cfgHandler.options["foursquare_password"])
print checkins
# check the date of the checkin .. if it is newer than the last update time then display
for checkin in checkins["checkins"]:
# check if we already have their avatar image otherwise get it
avatar_filename = os.path.basename(checkin["user"]["photo"])
if not os.path.isfile("cache/"+avatar_filename):
image = urllib.URLopener()
image.retrieve(checkin["user"]["photo"], "cache/"+avatar_filename)
notifymsg = checkin["display"] + "\n" + checkin["created"]
if checkin.has_key("shout"):
notifymsg = notifymsg + "\n\nShouted: \"" + checkin["shout"] + "\""
n = pynotify.Notification("Foursquare Checkin", notifymsg)
pixbuf_image = gtk.gdk.pixbuf_new_from_file("cache/"+avatar_filename)
n.set_icon_from_pixbuf(pixbuf_image)
n.set_timeout(3000)
n.show()
return True
def main():
gtk.main()
if __name__ == "__main__":
print "Starting Foursquare Notifier"
fs = FoursquareNotifier()
main()