summaryrefslogtreecommitdiff
path: root/weechat_notify.py
diff options
context:
space:
mode:
Diffstat (limited to 'weechat_notify.py')
-rwxr-xr-xweechat_notify.py48
1 files changed, 48 insertions, 0 deletions
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 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4import json
5import urllib2
6import sched
7import sys
8import time
9
10import pynotify
11
12POLLING_FREQUENCY = 10
13NOTIFICATION_URL = 'https://simeon.simeonov.no:40004/notifications/'
14TIMEOUT_SEC = 3
15
16def poll_notifications(scheduler):
17 """
18 """
19 try:
20 req = urllib2.Request(NOTIFICATION_URL)
21 response = urllib2.urlopen(req)
22 response_str = response.read()
23
24 entries = json.loads(response_str)
25 for entry in entries:
26 n = pynotify.Notification('IRC', entry, 'dialog-information')
27 n.set_timeout(TIMEOUT_SEC)
28 n.show()
29
30 except Exception as e:
31 sys.stderr.write("Client error: {0}".format(e))
32 sys.exit(1)
33
34 scheduler.enter(POLLING_FREQUENCY, 1, poll_notifications, (scheduler,))
35
36
37def main():
38
39 if not pynotify.init("Weechat Notify"):
40 sys.stderr.write("There was a problem with libnotify")
41 sys.exit(1)
42
43 sc = sched.scheduler(time.time, time.sleep)
44 sc.enter(POLLING_FREQUENCY, 1, poll_notifications, (sc,))
45 sc.run()
46
47if __name__ == '__main__':
48 main()