--- /dev/null
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# Depends: python-notify python-feedparser
+import sys
+import os.path
+import time
+import pynotify
+import feedparser
+
+SLEEP_TIME = 1800 # seconds
+
+if __name__ == '__main__':
+ print "DEBUG: Initialization..."
+ progname = os.path.basename(sys.argv[0])
+
+ # initialize the notification system
+ if not pynotify.init(progname):
+ print "FATAL: Unable to initialize the notification system!"
+ sys.exit(1)
+ notifier = pynotify.Notification(progname, "Initialization")
+ notifier.show()
+
+ # initialize the data
+ feeds = []
+ for url in sys.argv[1:]:
+ feeds.append({'url': url, 'etag': None, 'modified': time.gmtime(0)})
+ print "DEBUG: Watched feeds: %s" % [f['url'] for f in feeds]
+
+ # main loop
+ while True: # loop forever
+ for feed in feeds:
+ print "DEBUG: processing feed: %s" % feed
+ # check for last data
+ data = feedparser.parse(feed['url'], etag=feed['etag'],
+ modified=feed['modified'])
+ # process the result
+ if 'status' not in data: # parse error
+ print "ERROR: %s: %s" % (feed['url'], data['bozo_exception'])
+ elif data['status'] == 304: # no change
+ pass
+ elif data['status'] == 200: # parse ok
+ # update the feed data
+ feed['etag'] = data['etag']
+ feed['modified'] = data['updated']
+ # sort the notification array
+ entries = data['entries']
+ entries.sort(key=lambda e: e['updated_parsed'])
+ # notify about each entry
+ for entry in entries:
+ notifier.set_property('summary', entry['title'])
+ notifier.set_property('body', entry['summary'])
+ #notifier.set_urgency(pynotify.URGENCY_CRITICAL)
+ notifier.show()
+ # wait a bit before checking again
+ time.sleep(SLEEP_TIME)
+
+ sys.exit(0)