当前位置: 首页>>代码示例>>Python>>正文


Python Pushbullet.new_device方法代码示例

本文整理汇总了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)
开发者ID:rishikanthc,项目名称:ProjectBeacon,代码行数:12,代码来源:broadcast.py

示例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()
开发者ID:xbot,项目名称:SmartHome,代码行数:45,代码来源:main.py

示例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)
开发者ID:rishikanthc,项目名称:Mark2,代码行数:64,代码来源:pushlistener.py


注:本文中的pushbullet.Pushbullet.new_device方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。