diff options
| author | Simeon Simeonov | 2014-05-09 10:57:55 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2014-05-09 10:57:55 +0200 |
| commit | afe5b9815d8eb35eca518b77ab9d2bf8eb67a498 (patch) | |
| tree | d7154de909ce4f9a2e8bd27c09461d578db9a585 | |
| parent | 55638bcab6969219c7c46208ab9904b282007a75 (diff) | |
Few fixes
| -rwxr-xr-x | beinc_poller.py | 32 | ||||
| -rw-r--r-- | beinc_weechat.py | 6 |
2 files changed, 29 insertions, 9 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 | |||
| 35 | try: | 35 | try: |
| 36 | import pynotify | 36 | import pynotify |
| 37 | except ImportError as e: | 37 | except 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 | ||
| 77 | def poll_notifications(scheduler, args): | 78 | def 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 | ||
diff --git a/beinc_weechat.py b/beinc_weechat.py index 7c0841d..ceffef6 100644 --- a/beinc_weechat.py +++ b/beinc_weechat.py | |||
| @@ -266,7 +266,7 @@ class WeechatTarget(object): | |||
| 266 | '%n': values['own_nick']} | 266 | '%n': values['own_nick']} |
| 267 | for key, value in replacements.items(): | 267 | for key, value in replacements.items(): |
| 268 | template = template.replace(key, value) | 268 | template = template.replace(key, value) |
| 269 | return template | 269 | return template.encode('utf-8') |
| 270 | 270 | ||
| 271 | def __send_beinc_message(self, data): | 271 | def __send_beinc_message(self, data): |
| 272 | """ | 272 | """ |
| @@ -276,6 +276,8 @@ class WeechatTarget(object): | |||
| 276 | try: | 276 | try: |
| 277 | req = urllib2.Request(self.__url, data) | 277 | req = urllib2.Request(self.__url, data) |
| 278 | if self.__cert_file: | 278 | if self.__cert_file: |
| 279 | global global_beinc_cert_file | ||
| 280 | global_beinc_cert_file = self.__cert_file | ||
| 279 | opener = urllib2.build_opener(ValidHTTPSHandler) | 281 | opener = urllib2.build_opener(ValidHTTPSHandler) |
| 280 | response = opener.open(req) | 282 | response = opener.open(req) |
| 281 | else: | 283 | else: |
| @@ -381,7 +383,7 @@ def beinc_privmsg_handler(data, signal, signal_data): | |||
| 381 | ph_values['channel'] = prvmsg_dict['arguments'].split(':')[0].strip() | 383 | ph_values['channel'] = prvmsg_dict['arguments'].split(':')[0].strip() |
| 382 | ph_values['source_nick'] = prvmsg_dict['nick'] | 384 | ph_values['source_nick'] = prvmsg_dict['nick'] |
| 383 | ph_values['message'] = ':'.join( | 385 | ph_values['message'] = ':'.join( |
| 384 | prvmsg_dict['arguments'].split(':')[1:]).strip() | 386 | prvmsg_dict['arguments'].split(':')[1:]).strip().encode('utf-8') |
| 385 | if ph_values['channel'] == ph_values['own_nick']: | 387 | if ph_values['channel'] == ph_values['own_nick']: |
| 386 | # priv messages are handled here | 388 | # priv messages are handled here |
| 387 | if not global_values['global_private_messages_policy']: | 389 | if not global_values['global_private_messages_policy']: |
