summaryrefslogtreecommitdiff
path: root/beinc_poller.py
diff options
context:
space:
mode:
Diffstat (limited to 'beinc_poller.py')
-rwxr-xr-xbeinc_poller.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/beinc_poller.py b/beinc_poller.py
index aba6353..16cacd8 100755
--- a/beinc_poller.py
+++ b/beinc_poller.py
@@ -35,7 +35,8 @@ import urllib2
35try: 35try:
36 import pynotify 36 import pynotify
37except ImportError as e: 37except ImportError as e:
38 sys.stderr.write('A working pynotify library is required by BEINC-poller\n') 38 sys.stderr.write(
39 'A working pynotify library is required by BEINC-poller\n')
39 sys.exit(1) 40 sys.exit(1)
40 41
41 42
@@ -74,7 +75,7 @@ class ValidHTTPSHandler(urllib2.HTTPSHandler):
74 return self.do_open(ValidHTTPSConnection, req) 75 return self.do_open(ValidHTTPSConnection, req)
75 76
76 77
77def poll_notifications(scheduler, args): 78def poll_notifications(scheduler, args, notification_obj):
78 """ 79 """
79 """ 80 """
80 try: 81 try:
@@ -93,13 +94,16 @@ def poll_notifications(scheduler, args):
93 if res_code == 200 and args.debug: 94 if res_code == 200 and args.debug:
94 print('Server responded: OK') 95 print('Server responded: OK')
95 print('Body:\n{0}'.format(res_str)) 96 print('Body:\n{0}'.format(res_str))
96 res_list = json.loads(res_str)
97 print(type(res_list))
98 response.close() 97 response.close()
98 res_list = json.loads(res_str)
99 for entry in res_list:
100 notification_obj.set_properties(summary=entry.get('title', ''),
101 body=entry.get('message', ''))
102 notification_obj.show()
99 scheduler.enter(args.frequency, 103 scheduler.enter(args.frequency,
100 1, 104 1,
101 poll_notifications, 105 poll_notifications,
102 (scheduler, args)) 106 (scheduler, args, notification_obj))
103 except urllib2.HTTPError as e: 107 except urllib2.HTTPError as e:
104 sys.stderr.write('BEINC-server error ({0} - {1})\n'.format(e.code, 108 sys.stderr.write('BEINC-server error ({0} - {1})\n'.format(e.code,
105 e.reason)) 109 e.reason))
@@ -173,8 +177,22 @@ def main():
173 sys.stderr.write('There was a problem with libnotify\n') 177 sys.stderr.write('There was a problem with libnotify\n')
174 sys.exit(1) 178 sys.exit(1)
175 179
180 try:
181 notification_obj = pynotify.Notification(' ')
182 notification_obj.set_timeout(args.osd_timeout)
183 notification_obj.set_property(
184 'app_name',
185 '{0} {1}'.format(sys.argv[0], __version__))
186 except Exception as e:
187 sys.stderr.write(
188 'Unable to create pynotify Notification-object: {0}\n'.format(e))
189 sys.exit(1)
190
176 sc = sched.scheduler(time.time, time.sleep) 191 sc = sched.scheduler(time.time, time.sleep)
177 sc.enter(args.frequency, 1, poll_notifications, (sc, args)) 192 sc.enter(args.frequency,
193 1,
194 poll_notifications,
195 (sc, args, notification_obj))
178 sc.run() 196 sc.run()
179 197
180 198