本文整理匯總了Python中pushbullet.Pushbullet方法的典型用法代碼示例。如果您正苦於以下問題:Python pushbullet.Pushbullet方法的具體用法?Python pushbullet.Pushbullet怎麽用?Python pushbullet.Pushbullet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pushbullet
的用法示例。
在下文中一共展示了pushbullet.Pushbullet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def __init__(self, interface, url):
""" Initializes the PB WS Client"""
super().__init__(url)
self.pb = Pushbullet(cfg.PUSHBULLET_KEY)
self.manager = WebSocketManager()
self.interface = interface
self.device = None
for i, device in enumerate(self.pb.devices):
if device.nickname == cfg.PUSHBULLET_DEVICE:
logger.debug("Device found")
self.device = device
break
else:
logger.exception("Device not found. Creating 'pai' device")
self.device = self.pb.new_device(nickname='pai', icon='system')
示例2: __init__
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def __init__(self, token: str, device: str = 'Platypush', proxy_host: Optional[str] = None,
proxy_port: Optional[int] = None, **kwargs):
"""
:param token: Your Pushbullet API token, see https://docs.pushbullet.com/#authentication
:param device: Name of the virtual device for Platypush (default: Platypush)
:param proxy_host: HTTP proxy host (default: None)
:param proxy_port: HTTP proxy port (default: None)
"""
super().__init__(**kwargs)
self.token = token
self.device_name = device
self.proxy_host = proxy_host
self.proxy_port = proxy_port
self.device = None
self.pb_device_id = None
self.pb = None
self.listener = None
示例3: run
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
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()
# vim:sw=4:ts=4:et:
示例4: send_notification
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def send_notification(self, message):
api_keys = tuple(k.strip() for k in self.config['api_keys'].split(', '))
for key in api_keys:
device = None
if ':' in key:
device, key = key.split(':')
pb = pushbullet.Pushbullet(key)
if device:
try:
device = pb.get_device(device)
except pushbullet.errors.InvalidKeyError:
self.logger.error("failed to get pushbullet device: {0}".format(device))
try:
pb.push_note(self.config['identifier'], message, device=device)
except pushbullet.errors.PushError as error:
self.logger.error('failed to send the pushbullet note')
示例5: cli
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def cli():
"""A command line tool to download, convert
and send youtube videos or playlists to
your device via Pushbullet.
You need to install Pushbullet in all your devices
for this to work.
If this is your first time using this,
please run `moboff initialise` to add required
information.
Run `moboff download --help` to know about
various options while downloading and sending.
"""
pass
示例6: send_print_notification_pushbullet
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def send_print_notification_pushbullet(_print):
if not _print.printer.user.has_valid_pushbullet_token():
return
pb = Pushbullet(_print.printer.user.pushbullet_access_token)
title = 'The Spaghetti Detective - Print job notification'
link = site.build_full_url('/')
body = f"Your print job {_print.filename} {'has been canceled' if _print.is_canceled() else 'is done'} on printer {_print.printer.name}."
file_url = None
try:
file_url = _print.poster_url
if not ipaddress.ip_address(urlparse(file_url).hostname).is_global:
pb.upload_file(requests.get(file_url).content, 'Snapshot.jpg')
except:
pass
try:
if file_url:
pb.push_file(file_url=file_url, file_name="Snapshot.jpg", file_type="image/jpeg", body=body, title=title)
else:
pb.push_link(title, link, body)
except (PushError, PushbulletError) as e:
LOGGER.error(e)
示例7: __init__
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def __init__(self, spread_threshold: int, api_key: str) -> None:
super(Pushbullet, self).__init__(spread_threshold)
# ToDo: Raise error when api key is missing
if api_key == 'DEBUG':
self._pb = None
else:
self._pb = pb_lib.Pushbullet(api_key=api_key)
示例8: run
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def run(self, spreads: List[Spread], exchanges: List[Exchange], timestamp: float) -> None:
if not self._should_notify(settings.TIME_BETWEEN_NOTIFICATIONS):
return
spread = self._get_spread_for_notification(spreads)
if spread is not None:
logger.info('Notifying about spread via Pushbullet')
if self._pb is not None:
try:
self._pb.push_note(title=f'Spread {spread.spread_with_currency}', body=f'{spread.summary}')
except PushError as e:
logger.error(f'Cannot push spread via Pushbullet.\n{e}')
示例9: check_requirements
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def check_requirements(self):
try:
pb = Pushbullet(self.pushbullet_apikey)
except Exception as ex:
_logger.error("Cannot connect to your Pushbullet account. "
"Correct your config and try again. Error details:")
_logger.error(ex)
raise
_logger.info("Pushbullet server check passed")
示例10: notify
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def notify(self, title, text, url=None):
pb = Pushbullet(self.pushbullet_apikey)
push = pb.push_link(text, url)
示例11: received_message
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def received_message(self, message):
""" Handle Pushbullet message. It should be a command """
logger.debug("Received Message {}".format(message))
try:
message = json.loads(str(message))
except:
logger.exception("Unable to parse message")
return
if message['type'] == 'tickle' and message['subtype'] == 'push':
now = time.time()
pushes = self.pb.get_pushes(modified_after=int(now) - 20, limit=1, filter_inactive=True)
for p in pushes:
# Ignore messages send by us
if p.get('direction') == 'self' and p.get('title') == 'pai':
# logger.debug('Ignoring message sent')
continue
if p.get('direction') == 'outgoing' or p.get('dismissed'):
# logger.debug('Ignoring outgoing dismissed')
continue
if p.get('sender_email_normalized') in cfg.PUSHBULLET_CONTACTS or p.get('direction') == 'self':
future = asyncio.run_coroutine_threadsafe(
self.interface.handle_command(p.get('body')),
self.interface.alarm.work_loop
)
ret = future.result(10)
m = "PB {}: {}".format(p.get('sender_email_normalized'), ret)
logger.info(m)
else:
m = "PB {} (UNK): {}".format(p.get('sender_email_normalized'), p.get('body'))
logger.warning(m)
self.send_message(m)
ps.sendNotification(Notification(sender=self.name, message=m, level=EventLevel.INFO))
示例12: unhandled_error
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def unhandled_error(self, error):
logger.error("{}".format(error))
try:
self.terminate()
except Exception:
logger.exception("Closing Pushbullet WS")
self.close()
示例13: _run
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def _run(self):
super(PushbulletTextInterface, self)._run()
try:
self.pb_ws = PushBulletWSClient(self, 'wss://stream.pushbullet.com/websocket/{}'.format(cfg.PUSHBULLET_KEY))
self.pb_ws.connect()
except:
logger.exception("Could not connect to Pushbullet service")
logger.info("Pushbullet Interface Started")
示例14: stop
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def stop(self):
""" Stops the Pushbullet interface"""
super().stop()
if self.pb_ws is not None:
self.pb_ws.stop()
示例15: _initialize
# 需要導入模塊: import pushbullet [as 別名]
# 或者: from pushbullet import Pushbullet [as 別名]
def _initialize(self):
# noinspection PyPackageRequirements
from pushbullet import Pushbullet
self.pb = Pushbullet(self.token)
# noinspection PyBroadException
try:
self.device = self.pb.get_device(self.device_name)
except:
self.device = self.pb.new_device(self.device_name)
self.pb_device_id = self.get_device_id()