def initPBClient(): from lib.pushbullet import Pushbullet accessToken = __addon__.getSetting('pb_access_token') deviceIden = __addon__.getSetting('pb_client_iden') # init pushbullet pushbullet = Pushbullet(access_token=accessToken) pushbullet.setDeviceIden(deviceIden) return pushbullet
def run(self): """ Run or restart service. """ if self.pushbullet: common.log('Restarting') self.pushbullet.close() try: if not self.stg_pbAccessToken or not self.stg_pbClientIden: raise Exception(common.localise(30100)) from lib.pushbullet import Pushbullet # init pushbullet self.pushbullet = Pushbullet( access_token=self.stg_pbAccessToken, ping_timeout=6, last_modified=common.getSetting('last_modified', 0), last_modified_callback=self.setLastModified, log_callback=common.log) # get device info (also if edited by user on Pushbullet panel) self._getDevice() # setup service and pushbullet (iden, mirroring, filter) self._setupService() # start listening websocket self.pushbullet.realTimeEventStream( on_open=self.push2Notification.onOpen, on_message=self.push2Notification.onMessage, on_error=self.push2Notification.onError, on_close=self.push2Notification.onClose) common.log('Service started successfully') except Exception as ex: common.traceError() message = ' '.join(str(arg) for arg in ex.args) common.log(message, xbmc.LOGERROR) common.showNotification(common.localise(30101), message, self.serviceNotifcationTime)
from lib.requests.exceptions import ConnectionError except ImportError as e: print e sys.exit() args = alfred.args() if len(args) != 3: print 'Wrong number of parameters.' sys.exit() apiKey = args[0] deviceName = args[1] text = args[2] try: api = Pushbullet(apiKey) except InvalidKeyError: print 'API key is invalid.' sys.exit() except ConnectionError: print 'Failed connecting to pushbullet.' sys.exit() try: device = api.get_device(deviceName) except InvalidKeyError: print 'Device %s not found.' % deviceName sys.exit() try: device.push_note('', text)