class PushBulletAlert:
	def __init__(self, api_key, imagedir):
		self.pb = PushBullet(api_key)
		self.imagedir = imagedir

	def sendAlert(self, image):
		imagedata = open(os.path.join(self.imagedir, image), 'rb')
		success, file_data = self.pb.upload_file(imagedata, 'Motion detected: ' + image)
		success, push = self.pb.push_file(**file_data)
		return success 
class PushBulletAlert:
    def __init__(self, api_key, imagedir):
        self.pb = PushBullet(api_key)
        self.imagedir = imagedir

    def sendAlert(self, image):
        imagedata = open(os.path.join(self.imagedir, image), 'rb')
        success, file_data = self.pb.upload_file(imagedata,
                                                 'Motion detected: ' + image)
        success, push = self.pb.push_file(**file_data)
        return success
예제 #3
0
 def push(self):
     """ Push a task """
     p = PushBullet(self.api)
     if self.type == 'text':
         success, push = p.push_note(self.title, self.message)
     elif self.type == 'list':
         self.message = self.message.split(',')
         success, push = p.push_list(self.title, self.message)
     elif self.type == 'link':
         success, push = p.push_link(self.title, self.message)
     else:
         success, push = p.push_file(file_url=self.message, file_name="cat.jpg", file_type="image/jpeg")
예제 #4
0
def test_push_file_no_title_with_body(pb_push, pb_refresh):
    channel = Mock()
    channel.channel_tag = "tag1"

    pb = PushBullet("apikey")

    pb.push_file(
        "file_name.png",
        "file_url",
        "image/png",
        body="test image body",
        channel=channel,
    )

    pb_push.assert_called_with({
        "file_type": "image/png",
        "file_url": "file_url",
        "file_name": "file_name.png",
        "type": "file",
        "body": "test image body",
        "channel_tag": "tag1",
    })
예제 #5
0
def test_push_file_no_body_with_title(pb_push, pb_refresh):
    chat = Mock()
    chat.email = "*****@*****.**"

    pb = PushBullet("apikey")

    pb.push_file(
        "file_name.png",
        "file_url",
        "image/png",
        title="test image",
        chat=chat,
    )

    pb_push.assert_called_with({
        "file_type": "image/png",
        "file_url": "file_url",
        "file_name": "file_name.png",
        "type": "file",
        "title": "test image",
        "email": "*****@*****.**",
    })
예제 #6
0
def take_photo_and_push(pushbullet_auth_key, pushbullet_device_names):
    """ Takes a photo and sends to the cloud via PushBullet.
        Implements pushbullet.py, see https://pypi.python.org/pypi/pushbullet.py
        Implements picamera.py, see http://raspberrypi.org/picamera-pure-python-interface-for-camera-module
    """
    file_name = datetime.datetime.now().strftime("%I:%M%p %m-%d-%Y") + '.jpg'
    file_path = os.path.join('/home/pi', file_name)
    with picamera.PiCamera() as camera:
        camera.vflip = True
        camera.hflip = True
        camera.resolution = (1024, 768)
        camera.capture(file_path)

    pb = PushBullet(pushbullet_auth_key)

    with open(file_path, 'rb') as pic:
        message = 'SmartDoor ' + re.sub('.png', "", file_name)
        success, file_data = pb.upload_file(
            pic,
            message,
            'image/jpeg',
        )

    upload_message = "{0} uploading picture {1} to url {2}".format(
        'Success' if str(success) else 'Failure', file_data.get('file_name'),
        file_data.get('file_url'))
    print(upload_message)
    devices = pb.devices

    if any(
        [item in pushbullet_device_names for item in pushbullet_device_names]):
        for deviceName in pushbullet_device_names:
            device_list = [
                d for d in devices if d.nickname == deviceName and d.active
            ]
            device = device_list[0] if device_list else None
            if device is not None:
                success, push = device.push_file(**file_data)
                print('Successfully pushed ' + push.get('iden') + ' to ' +
                      device.nickname)
    else:
        success, push = pb.push_file(**file_data)
        print('Successfully pushed ' + push.get('iden') + ' to all devices')

    os.remove(file_path)
예제 #7
0
def take_photo_and_push(pushbullet_auth_key, pushbullet_device_names):
    """ Takes a photo and sends to the cloud via PushBullet.
        Implements pushbullet.py, see https://pypi.python.org/pypi/pushbullet.py
        Implements picamera.py, see http://raspberrypi.org/picamera-pure-python-interface-for-camera-module
    """
    file_name = datetime.datetime.now().strftime("%I:%M%p %m-%d-%Y") + '.jpg'
    file_path = os.path.join('/home/pi', file_name)
    with picamera.PiCamera() as camera:
        camera.vflip = True
        camera.hflip = True
        camera.resolution = (1024, 768)
        camera.capture(file_path)

    pb = PushBullet(pushbullet_auth_key)

    with open(file_path, 'rb') as pic:
        message = 'SmartDoor ' + re.sub('.png', "", file_name)
        success, file_data = pb.upload_file(pic, message, 'image/jpeg',)

    upload_message = "{0} uploading picture {1} to url {2}".format(
        'Success' if str(success) else 'Failure',
        file_data.get('file_name'),
        file_data.get('file_url'))
    print(upload_message)
    devices = pb.devices

    if any([item in pushbullet_device_names for item in pushbullet_device_names]):
        for deviceName in pushbullet_device_names:
            device_list = [d for d in devices if d.nickname == deviceName and d.active]
            device = device_list[0] if device_list else None
            if device is not None:
                success, push = device.push_file(**file_data)
                print('Successfully pushed ' + push.get('iden') + ' to ' + device.nickname)
    else:
        success, push = pb.push_file(**file_data)
        print('Successfully pushed ' + push.get('iden') + ' to all devices')

    os.remove(file_path)
#!/usr/python

from pushbullet import PushBullet
from subprocess import call
import time

pb = PushBullet('KEY_HERE')
while True:
	call(["streamer","-f", "jpeg", "-o","image.jpeg"])
	with open("image.jpeg", "rb") as pic:
   		success, file_data = pb.upload_file(pic, "picture.jpg")

	success, push = pb.push_file(**file_data)
	time.sleep(600)

예제 #9
0
from pushbullet import PushBullet

api_key = "q3U8S546S0D8tHJb8PrCzHaKABoHbnZy"

pb = PushBullet(api_key)
with open("gem1.png", "rb") as pic:
    file_data = pb.upload_file(pic, "gem1.png")

push = pb.push_file(**file_data)