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