From 5c2becae337ea7e2bcebec2912e4626d853b16aa Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Tue, 13 Nov 2012 15:40:27 +0100 Subject: All working with sqlite --- weechat_notify.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 weechat_notify.py (limited to 'weechat_notify.py') diff --git a/weechat_notify.py b/weechat_notify.py new file mode 100755 index 0000000..f070551 --- /dev/null +++ b/weechat_notify.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import json +import urllib2 +import sched +import sys +import time + +import pynotify + +POLLING_FREQUENCY = 10 +NOTIFICATION_URL = 'https://simeon.simeonov.no:40004/notifications/' +TIMEOUT_SEC = 3 + +def poll_notifications(scheduler): + """ + """ + try: + req = urllib2.Request(NOTIFICATION_URL) + response = urllib2.urlopen(req) + response_str = response.read() + + entries = json.loads(response_str) + for entry in entries: + n = pynotify.Notification('IRC', entry, 'dialog-information') + n.set_timeout(TIMEOUT_SEC) + n.show() + + except Exception as e: + sys.stderr.write("Client error: {0}".format(e)) + sys.exit(1) + + scheduler.enter(POLLING_FREQUENCY, 1, poll_notifications, (scheduler,)) + + +def main(): + + if not pynotify.init("Weechat Notify"): + sys.stderr.write("There was a problem with libnotify") + sys.exit(1) + + sc = sched.scheduler(time.time, time.sleep) + sc.enter(POLLING_FREQUENCY, 1, poll_notifications, (sc,)) + sc.run() + +if __name__ == '__main__': + main() -- cgit v1.3