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"]))
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"]))
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 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"]))
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))
frameIntercept[3] = frameIntercept[7] frameIntercept[4] = startX frameIntercept[5] = startY frameIntercept[6] = endX frameIntercept[7] = endY now = datetime.now() waktu = now.strftime("intruder\%d%m%Y_%H%M%S.png") waktuRapi = now.strftime("%H:%M:%S, %d %B %Y") print(inc) if (label == "No Mask") and (inc == 5): cv2.imwrite(waktu, frame) p.pushFile( devices[0]["iden"], waktu, "Ada pengunjung tanpa menggunakan masker!\nTerdeteksi pada jam " + waktuRapi, open(waktu, "rb")) label = "{}: {:.2f}%".format(label, max(mask, withoutMask) * 100) cv2.putText(frame, label, (startX, startY - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.45, color, 2) cv2.rectangle(frame, (startX, startY), (endX, endY), color, 2) if label == "Kosong": inc = 0 label = "Kosong" cv2.imshow("Frame", frame) key = cv2.waitKey(1) & 0xFF
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()
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 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))
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"]))
from pushbullet import PushBullet import json APIKEY = "o.PYxIZTSjuvOEbwlAhkF4StoRc548u0cS" CDNCHANNEL = "pushcdn" p = PushBullet(APIKEY) p.pushFile(CDNCHANNEL, "img.png", "File!", open("link.png", "rb"), recipient_type="channel_tag") print("Done!")
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.emitEvent('alertcontroller', "event.device.statechanged", STATE_PUSH_CONFIGURED, "") else: self.__configured = False client.emitEvent('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.setConfigOption('push', 'provider', 'pushbullet','alert') or not agoclient.setConfigOption('pushbullet', 'apikey', apikey, 'alert') or not agoclient.setConfigOption('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.emitEvent('alertcontroller', "event.device.statechanged", STATE_PUSH_CONFIGURED, "") return True def addPush(self, message, file): """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 _sendMessage(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))