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


Python Pushbullet.get_pushes方法代码示例

本文整理汇总了Python中pushbullet.Pushbullet.get_pushes方法的典型用法代码示例。如果您正苦于以下问题:Python Pushbullet.get_pushes方法的具体用法?Python Pushbullet.get_pushes怎么用?Python Pushbullet.get_pushes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pushbullet.Pushbullet的用法示例。


在下文中一共展示了Pushbullet.get_pushes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PushBulletRoute

# 需要导入模块: from pushbullet import Pushbullet [as 别名]
# 或者: from pushbullet.Pushbullet import get_pushes [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

示例2: ServicePushbullet

# 需要导入模块: from pushbullet import Pushbullet [as 别名]
# 或者: from pushbullet.Pushbullet import get_pushes [as 别名]
class ServicePushbullet(ServicesMgr):
    """
        Service Pushbullet
    """
    def __init__(self, token=None, **kwargs):
        super(ServicePushbullet, self).__init__(token, **kwargs)
        self.AUTH_URL = 'https://pushbullet.com/authorize'
        self.ACC_TOKEN = 'https://pushbullet.com/access_token'
        self.REQ_TOKEN = 'https://api.pushbullet.com/oauth2/token'
        self.consumer_key = settings.TH_PUSHBULLET_KEY['client_id']
        self.consumer_secret = settings.TH_PUSHBULLET_KEY['client_secret']
        self.scope = 'everything'
        self.service = 'ServicePushbullet'
        self.oauth = 'oauth2'
        if token:
            self.token = token
            self.pushb = Pushb(token)

    def read_data(self, **kwargs):
        """
            get the data from the service
            as the pushbullet service does not have any date
            in its API linked to the note,
            add the triggered date to the dict data
            thus the service will be triggered when data will be found

            :param kwargs: contain keyword args : trigger_id at least
            :type kwargs: dict

            :rtype: list
        """
        trigger_id = kwargs.get('trigger_id')
        trigger = Pushbullet.objects.get(trigger_id=trigger_id)
        date_triggered = kwargs.get('date_triggered')
        data = list()
        pushes = self.pushb.get_pushes()
        for p in pushes:
            title = 'From Pushbullet'
            created = arrow.get(p.get('created'))
            if created > date_triggered and p.get('type') == trigger.type and\
               (p.get('sender_email') == p.get('receiver_email') or p.get('sender_email') is None):
                title = title + ' Channel' if p.get('channel_iden') and p.get('title') is None else title
                # if sender_email and receiver_email are the same ;
                # that means that "I" made a note or something
                # if sender_email is None, then "an API" does the post

                body = p.get('body')
                data.append({'title': title, 'content': body})
                # digester
                self.send_digest_event(trigger_id, title, '')

        cache.set('th_pushbullet_' + str(trigger_id), data)
        return data

    def save_data(self, trigger_id, **data):
        """
            let's save the data
            :param trigger_id: trigger ID from which to save data
            :param data: the data to check to be used and save
            :type trigger_id: int
            :type data:  dict
            :return: the status of the save statement
            :rtype: boolean
        """
        title, content = super(ServicePushbullet, self).save_data(trigger_id, **data)
        if self.token:
            trigger = Pushbullet.objects.get(trigger_id=trigger_id)
            if trigger.type == 'note':
                status = self.pushb.push_note(title=title, body=content)
            elif trigger.type == 'link':
                status = self.pushb.push_link(title=title, body=content, url=data.get('link'))
                sentence = str('pushbullet {} created').format(title)
                logger.debug(sentence)
            else:
                # no valid type of pushbullet specified
                msg = "no valid type of pushbullet specified"
                logger.critical(msg)
                update_result(trigger_id, msg=msg, status=False)
                status = False
        else:
            msg = "no token or link provided for trigger ID {} ".format(trigger_id)
            logger.critical(msg)
            update_result(trigger_id, msg=msg, status=False)
            status = False
        return status
开发者ID:foxmask,项目名称:django-th,代码行数:87,代码来源:my_pushbullet.py

示例3: Pushlistener

# 需要导入模块: from pushbullet import Pushbullet [as 别名]
# 或者: from pushbullet.Pushbullet import get_pushes [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

示例4: notification

# 需要导入模块: from pushbullet import Pushbullet [as 别名]
# 或者: from pushbullet.Pushbullet import get_pushes [as 别名]
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)


def notification(pitch, duration):
    period = 1.0 / pitch
    delay = period / 2
    cycles = int(duration * pitch)
    for i in range(cycles):
        GPIO.output(pin, True)
        time.sleep(delay)
        GPIO.output(pin, False)
        time.sleep(delay)


while True:
    count = len(pb.get_pushes())
    pushes = pb.get_pushes()
    if count >= 1:
        if not pushes[0]['sender_email'] == me:
            notification(10, 0.5)
            time.sleep(0.25)
            notification(20, 0.5)
            time.sleep(0.25)
    else:
        GPIO.output(pin, GPIO.LOW)
    print 'Check In Progress'
    time.sleep(SLEEP)
开发者ID:AiGreek,项目名称:Raspberry-Scripts,代码行数:32,代码来源:push_notif.py


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