diff options
| author | Simeon Simeonov | 2012-11-13 15:40:27 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2012-11-13 15:40:27 +0100 |
| commit | 5c2becae337ea7e2bcebec2912e4626d853b16aa (patch) | |
| tree | 8176d6f36f1c9d758670bdd0c0752167af775ba7 /weechat_notify.py | |
| parent | b1b484a0b93a5651da7d1ca20e77f70089b215bb (diff) | |
All working with sqlite
Diffstat (limited to 'weechat_notify.py')
| -rwxr-xr-x | weechat_notify.py | 48 |
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 | |||
| 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 | def 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 | |||
| 37 | def 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 | |||
| 47 | if __name__ == '__main__': | ||
| 48 | main() | ||
