本文整理汇总了Python中pushbullet.Pushbullet.new_device方法的典型用法代码示例。如果您正苦于以下问题:Python Pushbullet.new_device方法的具体用法?Python Pushbullet.new_device怎么用?Python Pushbullet.new_device使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pushbullet.Pushbullet
的用法示例。
在下文中一共展示了Pushbullet.new_device方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: push
# 需要导入模块: from pushbullet import Pushbullet [as 别名]
# 或者: from pushbullet.Pushbullet import new_device [as 别名]
def push(msg):
api_key="kO3wYXQB6WQlQp7A5AN7WcPqdMOWy1Xx"
pb = Pushbullet(api_key)
# ip = subprocess.check_output("/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'", shell=True)
devlist=[x.nickname.encode('UTF-8') for x in pb.devices]
if 'Rpi' not in devlist:
pb.new_device('Rpi')
for dev in pb.devices:
push = dev.push_note('Rpi is up! ',msg)
示例2: PushBulletRoute
# 需要导入模块: from pushbullet import Pushbullet [as 别名]
# 或者: from pushbullet.Pushbullet import new_device [as 别名]
class PushBulletRoute(Route):
"""SmartHome using pushbullet."""
def __init__(self, cfg):
super(PushBulletRoute).__init__(cfg)
self.lastFetch = time.time()
self.apiKey = self.cfg.get('global', 'api_key')
self.pb = Pushbullet(self.apiKey)
def run(self):
try:
deviceIden = self.cfg.get('global', 'device_iden')
except NoOptionError:
deviceIden = self.pb.new_device('SmartHome').device_iden
self.cfg.set('global', 'device_iden', deviceIden)
with open(CONFIG_FILE, 'w') as f:
self.cfg.write(f)
def on_push(msg):
journal.send('Got message: ' + json.dumps(msg))
try:
pushes = self.pb.get_pushes(self.lastFetch)
journal.send('Got pushes: ' + json.dumps(pushes))
self.lastFetch = time.time()
if type(pushes) is types.TupleType and len(pushes)>1 \
and type(pushes[1]) is types.ListType:
for push in pushes[1]:
journal.send('Check push: ' + json.dumps(push))
if push.has_key('target_device_iden') and push['target_device_iden'] == deviceIden:
cmd = json.loads(push['body'])
self.home.followCommand(cmd)
fromIden = push['source_device_iden']
fromDevice = self.getDevice(fromIden)
if fromDevice is None:
journal.send('get_status: Cannot find device with iden "' + fromIden + '"', PRIORITY=journal.LOG_ERR)
return
self.pb.push_note('status', self.home.getStatus(), fromDevice)
except (PushbulletError, IOError, ValueError, KeyError), e:
journal.send(str(e), PRIORITY=journal.LOG_ERR)
lsr = Listener(Account(self.apiKey), on_push)
lsr.run()
示例3: Pushlistener
# 需要导入模块: from pushbullet import Pushbullet [as 别名]
# 或者: from pushbullet.Pushbullet import new_device [as 别名]
class Pushlistener(threading.Thread):
def __init__(self):
threading.Thread.__init__(self, name="PbThread")
self.api_key=api_key
self.pb = Pushbullet(self.api_key)
self.ws = websocket.WebSocket()
self.ws.connect("wss://stream.pushbullet.com/websocket/{0}".format(self.api_key))
self.last_time=0
self.data=''
self.setDaemon(True)
self.interpreters=[]
self.devices=[x.nickname.encode('UTF-8') for x in self.pb.devices]
if DEVICE_NAME not in self.devices:
self.pb.new_device('DEVICE_NAME')
def run(self):
while(1):
self.result=json.loads(self.ws.recv())
self.res_type=self.result.get("type")
if self.res_type!='nop':
self.context_matcher()
def context_matcher(self):
if self.result.get("type")=='tickle':
if self.result.get('subtype')=='push':
pushes = self.pb.get_pushes()
latest=pushes[1][0]
if latest.get('target_device_iden')==PUSHBULLET_ID:
self.body=latest['body']
os.system('mpg321 {0} 2>/dev/null'.format(MESSAGE_FILE))
self.notify({'text':self.body})
ny.show(self.body)
def register(self, interpreter):
"""
Register interpreters to be notified of new input
"""
if not interpreter in self.interpreters:
self.interpreters.append(interpreter)
def unregister(self, interpreter):
"""
Unregisters an interpreter
"""
if interpreter in self.interpreters:
self.interpreters.remove(interpreter)
def notify(self, event):
"""
Notify all interpreters of a received input
"""
for interpreter in self.interpreters:
interpreter.on_event(event, self)
def send(self,device,msg):
for dev in self.pb.devices:
print dev.nickname
if dev.nickname==device:
dev.push_note(msg,None)