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


Python PushBullet.getDevices方法代码示例

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


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

示例1: __init__

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import getDevices [as 别名]
class PBEventHandler:
    def __init__(self):
        self.KEY = KEY
        self.HIST_FILE = HIST_FILE
        self.pb = PushBullet(KEY)
        self.maxmod = float(0)
        self.iden = None
        
        self._sync_maxmod()
        self._sync_maxmod(self._get_modified())

        devices = self.pb.getDevices()
        for device in devices:
            if device['nickname'] == DEVICE:
                self.iden = device['iden']
                break


    def _get_modified(self):
        return self.pb.getPushHistory(self.maxmod)


    def _sync_maxmod(self, pushes = []):
        for push in pushes:
            if float(push['modified']) > self.maxmod:
                self.maxmod = float(push['modified'])

        n = float(self.maxmod)
        try:
            fn = float(open(self.HIST_FILE).read()) + 0.01
        except:
            fn = 0
        fn = max(float(n), float(fn))
        open(self.HIST_FILE, "w").write(str(fn))
        self.maxmod = float(fn)
        

    def _event(self, data, callback):
        if data['type'] == 'tickle' and data['subtype'] == 'push':
            pushes = self.pb.getPushHistory(self.maxmod)
            for push in pushes:
                if push['modified'] > self.maxmod:
                    self.maxmod = push['modified']
                self._sync_maxmod()

                if self.iden != None and\
                        push['target_device_iden'] != self.iden: continue
                try:
                    callback(push)
                except:
                    pass


    def run(self, callback):
        def __event(data):
            print "event: " + str(data)
            self._event(data, callback)

        self.pb.realtime(__event)
开发者ID:smrt28,项目名称:pyPushBullet,代码行数:61,代码来源:pbevents.py

示例2: getDevices

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import getDevices [as 别名]
def getDevices(args):
    p = PushBullet(args.api_key)
    devices = p.getDevices()
    if args.json:
        print(json.dumps(devices))
        return
    for device in devices:
        print("%s %s %s" % (device["iden"],
                            device["manufacturer"],
                            device["model"]))
开发者ID:Mondego,项目名称:pyreco,代码行数:12,代码来源:allPythonContent.py

示例3: getDevices

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import getDevices [as 别名]
def getDevices(args):
    p = PushBullet(args.api_key)
    try:
        devices = p.getDevices()
    except HTTPError:
        _, e, _ = sys.exc_info()
        print("The server couldn\'t fulfill the request.")
        print("Error code: %s" % (e.code))
    except URLError:
        _, e, _ = sys.exc_info()
        print("We failed to reach a server.")
        print("Reason: %s" % (e.reason))
    else:
        if args.json:
            print(devices)
            return
        for device in devices:
            if "nickname" in device["extras"]:
                print("%s %s" % (device["id"], device["extras"]["nickname"]))
            else:
                print("%s %s %s" % (device["id"], device["extras"]["manufacturer"], device["extras"]["model"]))
开发者ID:wimac,项目名称:home,代码行数:23,代码来源:pushbullet_cmd.py

示例4: socket

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import getDevices [as 别名]
import socket
import sys
import pushbullet
from pushbullet import PushBullet
from socket import socket, SOCK_DGRAM, AF_INET 

#getting IP address
s = socket(AF_INET, SOCK_DGRAM) 
s.connect(('google.com', 0))#using Google since it's pretty well always reachable
IP = s.getsockname()[0] #grab IP portion

#Make sure to put your api key here to work!
apiKey = "YOUR_API_KEY_HERE"

#create pushbullet obj and get list of devices
pb = PushBullet(apiKey)
devices = pb.getDevices()

#push IP to device!
pb.pushNote(devices[0]["id"], "IP Address", IP)
开发者ID:James-Firth,项目名称:raspbullet-ip-informer,代码行数:22,代码来源:raspberry-pibullet.py

示例5: PushBullet

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import getDevices [as 别名]
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import picamera
import datetime
from pushbullet import PushBullet
import os

apiKey = ""
p = PushBullet(apiKey)
devices = p.getDevices()

def removeoldpics():
	 os.remove(fileName)

def getFileName():
	return datetime.datetime.now().strftime ("%Y-%m-%d_%H.%M.%S.jpg")


	
sensorPin = 7

GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensorPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

prevState = False
currState = False

cam = picamera.PiCamera()

while True:
开发者ID:txt3rob,项目名称:pir-bullet,代码行数:33,代码来源:pirmine.py

示例6: Pushbullet

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import getDevices [as 别名]
class Pushbullet(AgoAlert):
    """Class for push message sending for ios and android
       @info https://www.pushbullet.com """
    def __init__(self, apikey, devices):
        """Constructor"""
        AgoAlert.__init__(self)
        global client
        self.name = 'pushbullet'
        self.pushbullet = None
        self.apikey = apikey
        if len(devices)==0:
            self.devices = []
        else:
            self.devices = json.loads(devices)
        self.pbdevices = {}
        self.pushTitle = 'Agocontrol'
        if apikey and len(apikey)>0 and devices and len(devices)>0:
            self.__configured = True
            self.pushbullet = PushBullet(self.apikey)
            client.emit_event('alertcontroller', "event.device.statechanged", STATE_PUSH_CONFIGURED, "")
        else:
            self.__configured = False
            client.emit_event('alertcontroller', "event.device.statechanged", STATE_PUSH_NOT_CONFIGURED, "")

    def getConfig(self):
        configured = 0
        if self.__configured:
            configured = 1
        return {'configured':configured, 'apikey':self.apikey, 'devices':self.devices, 'provider':self.name}

    def getPushbulletDevices(self, apikey=None):
        """request pushbullet to get its devices"""
        if not self.__configured and not apikey:
            logging.error('Pushbullet: unable to get devices. Not configured and no apikey specified')
            return {}
        
        if apikey:
            self.pushbullet = PushBullet(apikey)

        devices = []
        if self.pushbullet:
            devs = self.pushbullet.getDevices()
            logging.debug('pushbullet devs=%s' % str(devs))
            for dev in devs:
                name = '%s %s (%s)' % (dev['extras']['manufacturer'], dev['extras']['model'], dev['id'])
                self.pbdevices[name] = {'name':name, 'id':dev['id']}
                devices.append(name)
        else:
            logging.error('Pushbullet: unable to get devices because not configured')
        return devices

    def setConfig(self, apikey, devices):
        """set config
           @param apikey: pushbullet apikey (available on https://www.pushbullet.com/account)
           @param devices: array of devices (id) to send notifications """
        if not apikey or len(apikey)==0 or not devices or len(devices)==0:
            logging.error('Pushbullet: all parameters are mandatory')
            return False
        if not agoclient.set_config_option('push', 'provider', 'pushbullet','alert') or not agoclient.set_config_option('pushbullet', 'apikey', apikey, 'alert') or not agoclient.set_config_option('pushbullet', 'devices', json.dumps(devices), 'alert'):
            logging.error('Pushbullet: unable to save config')
            return False
        self.apikey = apikey
        self.devices = devices
        self.pbdevices = {}
        self.pushbullet = PushBullet(self.apikey)
        self.__configured = True
        client.emit_event('alertcontroller', "event.device.statechanged", STATE_PUSH_CONFIGURED, "")
        return True

    def addPush(self, message, file=None):
        """Add push
           @param message: push notification
           @file: full file path to send"""
        if self.__configured:
            #check params
            if not message or len(message)==0:
                if not file or len(file)==0:
                    logging.error('Pushbullet: Unable to add push (at least one parameter is mandatory)')
                    return False
            elif not file or len(file)==0:
                if not message or len(message)==0:
                    logging.error('Pushbullet: Unable to add push (at least one parameter is mandatory)')
                    return False
            if message==None:
                message = ''
            if file==None:
                file = ''
            #queue push message
            self._addMessage({'message':message, 'file':file})
            return True
        else:
            logging.error('Pushover: unable to add message because not configured')
            return False

    def _send_message(self, message):
        #get devices from pushbullet if necessary
        if len(self.pbdevices)==0:
            self.getPushbulletDevices()

        #push message
#.........这里部分代码省略.........
开发者ID:yjc2003,项目名称:raspberry,代码行数:103,代码来源:agoalert.py


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