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


Python PushBullet.pushFile方法代码示例

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


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

示例1: pushFile

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import pushFile [as 别名]
def pushFile(args):
    p = PushBullet(args.api_key)
    file = p.pushFile(args.device, open(args.file, 'rb'))
    if args.json:
        print(json.dumps(file))
        return
    print("File %s sent to %s" % (file["iden"], file["target_device_iden"]))
开发者ID:Mondego,项目名称:pyreco,代码行数:9,代码来源:allPythonContent.py

示例2: pushFile

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import pushFile [as 别名]
def pushFile(args):
    p = PushBullet(args.api_key)
    file = p.pushFile(args.device, os.path.basename(args.file), "", open(args.file, 'rb'))
    if args.json:
        print(json.dumps(file))
        return
    if args.device and args.device[0] == '#':
        print("File broadcast to channel %s" % (args.device))
    elif not args.device:
        print("File %s sent to all devices" % (file["iden"]))
    else:
        print("File %s sent to %s" % (file["iden"], file["target_device_iden"]))
开发者ID:kakai248,项目名称:pyPushBullet,代码行数:14,代码来源:pushbullet_cmd.py

示例3: pushFile

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import pushFile [as 别名]
def pushFile(args):
    p = PushBullet(args.api_key)
    try:
        file = p.pushFile(args.device, args.file)
    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(file)
            return
        if "created" in file:
            print("OK")
        else:
            print("ERROR %s" % (file))
开发者ID:wimac,项目名称:home,代码行数:22,代码来源:pushbullet_cmd.py

示例4: getFileName

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import pushFile [as 别名]
	
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:
	time.sleep(.1)
	prevState = currState
	currState = GPIO.input(sensorPin)
	if currState != prevState:
		print "GPIO pin {0} is {1}".format(sensorPin, "HIGH" if currState else "LOW")
		if currState:
			fileName = getFileName()
			cam.start_preview()
			cam.capture(fileName)
			p.pushFile(devices[0]["iden"], "Intruder Alert!", "Image From PiCam", open(fileName, "rb"))
			cam.stop_preview()
			time.sleep(5)
			removeoldpics()
		else:
			cam.stop_preview()
			
			
开发者ID:txt3rob,项目名称:pir-bullet,代码行数:29,代码来源:pirmine.py

示例5: Pushbullet

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import pushFile [as 别名]

#.........这里部分代码省略.........
        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
        for device in self.devices:
            #get device id
            if self.pbdevices.has_key(device):
                if len(message['file'])==0:
                    #send a note
                    resp = self.pushbullet.pushNote(self.pbdevices[device]['id'], self.pushTitle, message['message'])
                    logging.info(resp)
                else:
                    #send a file
                    resp = self.pushbullet.pushFile(self.pbdevices[device]['id'], message['file'])
            else:
                logging.warning('Pushbullet: unable to push notification to device "%s" because not found' % (device))
开发者ID:yjc2003,项目名称:raspberry,代码行数:104,代码来源:agoalert.py

示例6: PushBullet

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import pushFile [as 别名]
import sys
import json
import os
from pushbullet import PushBullet
from requests.exceptions import HTTPError

if __name__ == '__main__':
	p = PushBullet("L0Wtxg0coFfVW4majBbORq3sS3xkQmTF")

	devices = p.getDevices()

	# Get a list of contacts
	contacts = p.getContacts()

	# Send a note
	#p.pushNote(devices[0]["iden"], 'Hello world', 'Test body')

	p.pushFile(devices[0]["iden"], "take-photo-test5.jpg", "This is a test file", open("/home/pi/RPiWebCam/Test/take-photo-test5.jpg", "rb"))

    #note = p.pushNote(args.device, args.title, " ".join(args.body))
    #if args.json:
    #    print(json.dumps(note))
    #    return
    #if args.device and args.device[0] == '#':
    #    print("Note broadcast to channel %s" % (args.device))
    #elif not args.device:
    #    print("Note %s sent to all devices" % (note["iden"]))
    #else:
    #    print("Note %s sent to %s" % (note["iden"], note["target_device_iden"]))
开发者ID:zag2k,项目名称:RPiTest,代码行数:31,代码来源:pushtest.py


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