def __init__(self, auth_key, device_name, last_push=time.time(), device_iden=None): self._auth_key = auth_key self.pb = PushBullet(self._auth_key) self.listener = Listener(self.pb, self.download_link) self.last_push = last_push self.device = None if device_iden: results = [ d for d in self.pb.devices if d.device_iden == device_iden and d.active ] self.device = results[0] if results else None if not self.device: try: device = self.pb.new_device(device_name) print("Created new device:", device_name, "iden:", device.device_iden) self.device = device except: print("Error: Unable to create device") raise
def __init__(self, auth_key, temp_folder, device_name, last_push=time.time(), device_iden=None): self.temp_folder = temp_folder if not os.path.exists(self.temp_folder): os.makedirs(temp_folder) self._auth_key = auth_key self.pb = PushBullet(self._auth_key) self.listener = Listener(self.pb, self.watcher) self.last_push = last_push self.device = None if device_iden: results = [d for d in self.pb.devices if d.device_iden == device_iden and d.active] self.device = results[0] if results else None if not self.device: try: device = self.pb.new_device(device_name) print("Created new device:", device_name, "iden:", device.device_iden) self.device = device except Exception: print("Error: Unable to create device") raise self.check_pushes()
def __init__(self, auth_key, temp_folder, device_name, last_push=0, device_iden=None): self.temp_folder = temp_folder if not os.path.exists(self.temp_folder): os.makedirs(temp_folder) self._auth_key = auth_key self.pb = PushBullet(self._auth_key) self.listener = Listener(self.pb, self.watcher) self.last_push = last_push self.device = None if device_iden: results = [ d for d in self.pb.devices if d.device_iden == device_iden and d.active ] self.device = results[0] if results else None if not self.device: success, device = self.pb.new_device(device_name) if success: self.device = device else: print("Error ") print(device) self.check_pushes()
def post(self): pb = Pushbullet(API_KEY) push = pb.push_note(title, note) s = Listener(account=pb, on_push=on_push, http_proxy_host=HTTP_PROXY_HOST, http_proxy_port=HTTP_PROXY_PORT)
def main(): global logger global pidfile global API_KEY global is_alive is_alive = 0 API_KEY = sys.argv[1] logger = logger_init('pushbullet', True) logger.debug("Check PID file") path = os.path.dirname(os.path.realpath(__file__)) + '/../../../../tmp' try: os.makedirs(path) except OSError: if not os.path.isdir(path): raise pidfile = path + '/pushbullet.' + API_KEY + '.pid' createpid = True logger.debug("PID file '" + pidfile + "'") if os.path.exists(pidfile): print("PID file '" + pidfile + "' already exists. Exiting.") logger.debug("PID file '" + pidfile + "' already exists.") logger.debug("Exit 1") sys.exit(1) try: logger.debug("Write PID file") file(pidfile, 'w').write("pid\n") except IOError as e: #logger.error("Line: " + _line()) logger.error("Unable to write PID file: %s [%d]" % (e.strerror, e.errno)) raise SystemExit("Unable to write PID file: %s [%d]" % (e.strerror, e.errno)) logger.debug("Start daemon") daemonize() s = Listener(api_key=API_KEY, on_push=on_push, http_proxy_host=HTTP_PROXY_HOST, http_proxy_port=HTTP_PROXY_PORT) s.run_forever() t = Timer(60, timeout) t.start() sys.exit(0)
def _connect(cls, queue): if cls.key and cls.users: cls.pb = Pushbullet(cls.key) cls.handler = PushHandler(cls.users, cls.pb, queue) cls.ear = Listener(account=cls.pb, on_push=cls.handler.catch, http_proxy_host=cls.HPH, http_proxy_port=cls.HPP) else: raise SettingsError('Please check info in your settings.py file')
def main(): s = Listener(API_KEY, device_id=DEVICE_ID, on_link=on_link, http_proxy_host=HTTP_PROXY_HOST, http_proxy_port=HTTP_PROXY_PORT) try: s.run_forever() except KeyboardInterrupt: s.close()
def main(): s = Listener(account=pb, on_push=on_push, http_proxy_host=HTTP_PROXY_HOST, http_proxy_port=HTTP_PROXY_PORT) try: s.run_forever() except KeyboardInterrupt: s.close()
def run(self): super().run() self.logger.info('Initialized Pushbullet backend - device_id: {}' .format(self.device_name)) self.listener = Listener(account=self.pb, on_push=self.on_push(), http_proxy_host=self.proxy_host, http_proxy_port=self.proxy_port) self.listener.run_forever()
def main(): global pb push = pb.push_note("This is the title", "This is the body") s = Listener(account=pb, on_push=on_push, http_proxy_host=HTTP_PROXY_HOST, http_proxy_port=HTTP_PROXY_PORT) try: s.run_forever() except KeyboardInterrupt: s.close()
def retrieve_pushes(self): """Retrieve_pushes. Spawn a new Listener and links it to self.on_push. """ from pushbullet import Listener self.listener = Listener(account=self.pushbullet, on_push=self.on_push) _LOGGER.debug("Getting pushes") try: self.listener.run_forever() finally: self.listener.close()
def run_listener(self): from pushbullet import Listener self.logger.info( 'Initializing Pushbullet backend - device_id: {}'.format( self.device_name)) self.listener = Listener(account=self.pb, on_push=self.on_push(), on_error=self.on_error, http_proxy_host=self.proxy_host, http_proxy_port=self.proxy_port) self.listener.run_forever()
def __init__(self): """Create PushBullet listener.""" self.logger = logging.getLogger(__name__) self.logger.info("Starting PushbulletManager...") self.pb = Pushbullet(os.environ.get("PUSHBULLET_API_TOKEN")) push_list = self.pb.get_pushes(limit=1) if push_list: self.last_mod_time = push_list[0]["modified"] self.pb_listener = Listener(account=self.pb, on_push=self.pb_on_push, on_error=self.pb_on_error, http_proxy_host=HTTP_PROXY_HOST, http_proxy_port=HTTP_PROXY_PORT) self.rmc = ReminderMessageConsumer() self.rmc.start()
def run(self): # noinspection PyPackageRequirements from pushbullet import Listener super().run() self.logger.info( 'Initialized Pushbullet backend - device_id: {}'.format( self.device_name)) self.listener = Listener(account=self.pb, on_push=self.on_push(), http_proxy_host=self.proxy_host, http_proxy_port=self.proxy_port) self.listener.run_forever()
def run(self): # noinspection PyPackageRequirements from pushbullet import Listener super().run() initialized = False while not initialized: try: self._initialize() initialized = True except Exception as e: self.logger.exception(e) self.logger.error('Pushbullet initialization error: {}'.format(str(e))) time.sleep(30) self.logger.info('Initialized Pushbullet backend - device_id: {}' .format(self.device_name)) self.listener = Listener(account=self.pb, on_push=self.on_push(), http_proxy_host=self.proxy_host, http_proxy_port=self.proxy_port) self.listener.run_forever()
def test_listener_init(): pb = PushBullet("apikey") listener = Listener(pb) listener.close()
def on_push(data): pushes = pb.get_pushes() latest = pushes[1][0] if 'TodaysWeather' in latest.get('title'): body = latest.get('body') if any(x in body for x in ['Sunny', 'Clear']): GPIO.output(greenPin, True) elif 'Cloud' in body: GPIO.output(yellowPin, True) elif any(x in body for x in ['Rain', 'Shower', 'Snow']): GPIO.output(redPin, True) # sleep 1 hour time.sleep(3600) leds_off() if __name__ == "__main__": pb = PushBullet(api_key) s = Listener(account=pb, on_push=on_push, http_proxy_host=HTTP_PROXY_HOST, http_proxy_port=HTTP_PROXY_PORT) init_leds() try: s.run_forever() except KeyboardInterrupt: s.close() leds_off()
def __createListener(self): self.listener = Listener(account=self.pushBulletManager, on_push=self.on_push, http_proxy_host=HTTP_PROXY_HOST, http_proxy_port=HTTP_PROXY_PORT) self.listener.run_forever()
logger.debug("Exit 1") sys.exit(1) try: logger.debug("Write PID file") file(pidfile, 'w').write("pid\n") except IOError, e: #logger.error("Line: " + _line()) logger.error("Unable to write PID file: %s [%d]" % (e.strerror, e.errno)) raise SystemExit("Unable to write PID file: %s [%d]" % (e.strerror, e.errno)) logger.debug("Start daemon") daemonize() s = Listener(api_key=API_KEY, on_push=on_push, http_proxy_host=HTTP_PROXY_HOST, http_proxy_port=HTTP_PROXY_PORT) s.run_forever() t = Timer(60, timeout) t.start() sys.exit(0) def timeout(push): global is_alive if is_alive == 0: sys.exit(0)