2 # -*- coding: utf-8 -*-
3 # Depends: python-notify python-feedparser
10 SLEEP_TIME
= 1800 # seconds
12 if __name__
== '__main__':
13 print "DEBUG: Initialization..."
14 progname
= os
.path
.basename(sys
.argv
[0])
16 # initialize the notification system
17 if not pynotify
.init(progname
):
18 print "FATAL: Unable to initialize the notification system!"
20 notifier
= pynotify
.Notification(progname
, "Initialization")
25 for url
in sys
.argv
[1:]:
26 feeds
.append({'url': url
, 'etag': None, 'modified': time
.gmtime(0)})
27 print "DEBUG: Watched feeds: %s" % [f
['url'] for f
in feeds
]
30 while True: # loop forever
32 print "DEBUG: processing feed: %s" % feed
34 data
= feedparser
.parse(feed
['url'], etag
=feed
['etag'],
35 modified
=feed
['modified'])
37 if 'status' not in data
: # parse error
38 print "ERROR: %s: %s" % (feed
['url'], data
['bozo_exception'])
39 elif data
['status'] == 304: # no change
41 elif data
['status'] == 200: # parse ok
42 # update the feed data
43 feed
['etag'] = data
['etag']
44 feed
['modified'] = data
['updated']
45 # sort the notification array
46 entries
= data
['entries']
47 entries
.sort(key
=lambda e
: e
['updated_parsed'])
48 # notify about each entry
50 notifier
.set_property('summary', entry
['title'])
51 notifier
.set_property('body', entry
['summary'])
52 #notifier.set_urgency(pynotify.URGENCY_CRITICAL)
54 # wait a bit before checking again
55 time
.sleep(SLEEP_TIME
)