Пример #1
0
    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
Пример #2
0
    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()
Пример #3
0
    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()
Пример #4
0
    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)
Пример #5
0
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)
Пример #6
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')
Пример #7
0
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()
Пример #8
0
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()
Пример #9
0
    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()
Пример #10
0
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()
Пример #11
0
    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()
Пример #12
0
    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()
Пример #13
0
 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()
Пример #14
0
    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()
Пример #15
0
    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()
Пример #16
0
def test_listener_init():
    pb = PushBullet("apikey")

    listener = Listener(pb)

    listener.close()
Пример #17
0
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()
Пример #18
0
 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()
Пример #19
0
		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)