def recog(): visitor=0 known_encoding = face_recognition.face_encodings(known_image)[0] print('known image encodings done') previous_state = False current_state = False while True: previous_state=current_state current_state=GPIO.input(sensor) if(current_state != previous_state): if(current_state): new_state="HIGH" else: new_state="LOW" print("GPIO pin %s is %s" % (sensor,new_state)) if(current_state): print("A photo will be taken in 3 seconds") time.sleep(3) with picamera.PiCamera() as camera: camera.resolution = (340, 220) time.sleep(2) camera.capture('unknown.jpg') unknown_image = face_recognition.load_image_file("/home/pi/Desktop/unknown.jpg") face_locations = face_recognition.face_locations(unknown_image) if(len(face_locations) == 0): print("no face detected") os.remove('unknown.jpg') continue unknown_encoding = face_recognition.face_encodings(unknown_image)[0] print("encodings calculated") results = face_recognition.compare_faces([known_encoding], unknown_encoding) print(results) if results == [True]: GPIO.setup(14, GPIO.OUT) print("person recognised,frank") p = PushBullet("o.a441em4dWH3fzGm1mcURidwfuJ1gG4Jn") #secret key of pushbullet API devices = p.getDevices() p.pushNote(devices[0]["iden"], 'Frank is at the door', 'open the door') os.remove("unknown.jpg") print("message sent") GPIO.cleanup() break else: while(os.path.exists("/home/pi/Desktop/known/"+str(visitor)+".jpg")): visitor=visitor+1 os.rename("/home/pi/Desktop/unknown.jpg","/home/pi/Desktop/"+str(visitor)+".jpg") shutil.move("/home/pi/Desktop/"+str(visitor)+".jpg","/home/pi/Desktop/known") print("unknown person") picname = str(visitor) + ".jpg" visitor=visitor+1 #cv2.imwrite(picname,frame) p = PushBullet("o.a441em4dWH3fzGm1mcURidwfuJ1gG4Jn") #secret key of pushbullet API devices = p.getDevices() p.pushFile(devices[0]["iden"], picname, "unknown person", open("/home/pi/Desktop/known/"+picname, "rb")) print("Sending email") attach=picname #attachments to send with email smail.send_mail(attach) print("email sent") break
def connect(self): apiKey = "o.2uIo9r0MKCCFX8Mv3uMhp4xOXE9vgBrC" p = PushBullet(apiKey) # Get a list of devices devices = p.getDevices() msg, ct, ch = self.blueMsg() while True: botList = self.detect() print(botList) if devices[0].get("nickname") in botList: print("Found device with names: ", botList) p.pushNote( devices[0]["iden"], 'Raspberry-Pi-Notification', 'Current Temperature is :' + str(ct) + 'Degrees' + '\nCurrentHumid :' + str(ch) + '%' + '\n' + msg) break
def plugin(srv, item): ''' expects (apikey, device_id) in adddrs ''' srv.logging.debug("*** MODULE=%s: service=%s, target=%s", __file__, item.service, item.target) if not HAVE_PUSHBULLET: srv.logging.warn("pushbullet is not installed") return False try: apikey, device_id = item.addrs except: srv.logging.warn("pushbullet target is incorrectly configured") return False text = item.message title = item.get('title', srv.SCRIPTNAME) try: srv.logging.debug("Sending pushbullet notification to %s..." % (item.target)) pb = PushBullet(apikey) pb.pushNote(device_id, title, text) srv.logging.debug("Successfully sent pushbullet notification") except Exception, e: srv.logging.warning("Cannot notify pushbullet: %s" % (str(e))) return False
def compare_collections(): myclient = pymongo.MongoClient("mongodb://localhost:27017/") db = myclient["Takealot_DB"] collectionA = "graphics_cards_day_{}".format(initial_day) collectionB = "graphics_cards_day_{}".format(next_day) print(collectionA, collectionB) apiKey = "GET YOUR OWN API KEY" p = PushBullet(apiKey) # Get a list of devices devices = p.getDevices() x = get_var_value() print("THIS IS THE VARSTORE VALUE: {}".format(x)) y = x - 1 print("THIS IS THE VARSTORE VALUE MINUS 1: {}".format(y)) if x < 2: print("Nothing to compare. Program must run at least twice.") else: for item in db.get_collection(collectionA).find(): item_name = item['item_name'] item2 = db.get_collection(collectionB).find_one( {'item_name': item_name}) result = "\n Price change is {} for item {} with original price being {} in collection A,\n and item {} with original price being {} in collection B.\n The difference is {}".format( item['item_price'] > item2['item_price'], item['item_name'], item['item_price'], item2['item_name'], item2['item_price'], item['item_price'] - item2['item_price']) p.pushNote(devices[0]["iden"], 'Scraping completed', result)
def plugin(srv, item): ''' expects (apikey, device_id) in adddrs ''' srv.logging.debug("*** MODULE=%s: service=%s, target=%s", __file__, item.service, item.target) recipient_type = "device_iden" try: apikey, device_id = item.addrs except: try: apikey, device_id, recipient_type = item.addrs except: srv.logging.warn("pushbullet target is incorrectly configured") return False text = item.message title = item.get('title', srv.SCRIPTNAME) try: srv.logging.debug("Sending pushbullet notification to %s..." % (item.target)) pb = PushBullet(apikey) pb.pushNote(device_id, title, text, recipient_type) srv.logging.debug("Successfully sent pushbullet notification") except Exception as e: srv.logging.warning("Cannot notify pushbullet: %s" % e) return False return True
def push(self, token, notification_info): try: pb = PushBullet(token) pbDevices = pb.devices except Exception, e: print e return False
def addDevice(args): p = PushBullet(args.api_key) devices = p.addDevice(args.nickname) if args.json: print(json.dumps(devices)) return print("Device %s was assigned ID %s" % (devices["nickname"], devices["iden"]))
def main(): #setup our reddit instance reddit = praw.Reddit(client_id=CLIENT_KEY, client_secret=SECRET_KEY, user_agent=USERNAME) #setup our pushbullet instance push = PushBullet(API_KEY) loop_through_posts(reddit=reddit, push=push)
def pushBullet(title, message): try: from pushbullet.pushbullet import PushBullet apiKey = "o.mKznlsIJB18uq6qArGrl2AOPU2KbISsR" p = PushBullet(apiKey) devices = p.getDevices() p.pushNote(devices[0]["iden"], title, message) except Exception, e: logger.exception(e)
def sendNotif(self, header, body): if self.apiKey == "": fichier = open("api.txt", "r") self.apiKey = fichier.read()[:-1] # attention retour a la ligne fichier.close() p = PushBullet(self.apiKey) devices = p.getDevices() for i in range(len(devices)): p.pushNote(devices[i]["iden"], header, body)
def sendNotif(): pb = PushBullet("o.sqTG7BlAEOoQDpccJ2n3nFwZ4BRy2637") devices = pb.getDevices() title = "Recolteur d'eau" text = "Le reservoir est vide!" for device in devices: if device['pushable']: note = pb.pushNote(device["iden"], title, text)
def pushLink(args): p = PushBullet(args.api_key) link = p.pushLink(args.device, args.title, args.url) if args.json: print(json.dumps(link)) return if args.device and args.device[0] == '#': print("Link broadcast to channel %s" % (args.device)) elif not args.device: print("Link %s sent to all devices" % (link["iden"])) else: print("Link %s sent to %s" % (link["iden"], link["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 pushNote(args): p = PushBullet(args.api_key) 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"]))
def pushAddress(args): p = PushBullet(args.api_key) address = p.pushAddress(args.device, args.name, " ".join(args.address)) if args.json: print(json.dumps(address)) return if args.device and args.device[0] == '#': print("Address broadcast to channel %s" % (args.device)) elif not args.device: print("Address %s sent to all devices" % (address["iden"])) else: print("Address %s sent to %s" % (address["iden"], address["target_device_iden"]))
def getDevices(args): p = PushBullet(args.api_key) devices = p.getDevices() if args.json: print(json.dumps(devices)) return for device in devices: if "manufacturer" in device: print("%s %s %s" % (device["iden"], device["manufacturer"], device["model"])) else: print(device["iden"])
def sendNotify(self, msg): # pushBullet notify call for registerd devices apiKey = "o.2uIo9r0MKCCFX8Mv3uMhp4xOXE9vgBrC" p = PushBullet(apiKey) devices = p.getDevices() p.pushNote(devices[0]["iden"], 'Raspberry-Pi-Notification', msg)
def register_device(): if config.has_option("main", "device_iden"): return r = pushbullet.addDevice("gtk-pushbullet") config.set("main", "device_iden", r["iden"]) config.save() print("Registered device 'gtk-pushbullet', iden: " + r["iden"]) config = GtkPushBulletConfig() if not config.has_option("main", "api_key"): sys.stderr.write("Error: api_key is not set\n") sys.exit(1) Notify.init('net.lyude.pushbullet.notifications') pushbullet = PushBullet(config.get("main", "api_key")) register_device() print("Connected, listening for notifications...") event_stream_thread = EventStreamThread(pushbullet, config) event_stream_thread.start() signal.signal(signal.SIGINT, signal.SIG_DFL) Gtk.main()
def notifyuser(): p = PushBullet(apiKey) devices = p.getDevices() print(devices) p.pushNote(devices[0]["iden"], 'Smart Home Manager', 'Intruder Detected')
def notify_neighbor(name): p = PushBullet(apiKey) devices = p.getDevices() print(devices) response="Intruder Detected in {}'s Home. Please check.".format(name) p.pushNote(devices[0]["iden"], 'Smart Home Manager', response)
def notifyuser_place(msg): p = PushBullet(apiKey) devices = p.getDevices() print(devices) p.pushNote(devices[0]["iden"], 'Smart Home Manager', 'Intruder Detected in {}'.format(msg))
from pushbullet.pushbullet import PushBullet api_key = '' pb = PushBullet(api_key) # Get a list of devices devices = pb.getDevices() print(devices) # test values albumURI = "1231232141sdasd" deviceID = "123214123212" # Send a note note_title = 'Played ' + albumURI note_body = 'Song played on ' + deviceID pb.pushNote(devices[1]["iden"], note_title, note_body)
def displayPushBulletDevices(apiKey): p = PushBullet(apiKey) devices = p.getDevices() print(devices)
"/home/roark/AutoAccessCowin/cowin-vaccination-slot-availabilityv2/PreviousAvailabilityShelf", writeback=True) else: shelf = shelve.open( "/home/roark/AutoAccessCowin/cowin-vaccination-slot-availabilityv2/PreviousAvailabilityShelf", writeback=True) shelf['previousavailability'] = False numdays = 7 DIST_ID = '170' config_object = ConfigParser() config_object.read("config.ini") auth = config_object["AUTH"]["api_key"] print(auth) p = PushBullet(auth) base = datetime.datetime.today() date_list = [base + datetime.timedelta(days=x) for x in range(numdays)] date_str = [x.strftime("%d-%m-%Y") for x in date_list] temp_user_agent = UserAgent() browser_header = {'User-Agent': temp_user_agent.random} for INP_DATE in date_str: URL = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id={}&date={}".format( DIST_ID, INP_DATE) response = requests.get(URL, headers=browser_header) if (response.ok) and ('centers' in json.loads(response.text)): resp_json = json.loads(response.text)['centers'] if (resp_json is not None):
def sendPushBulletEmail(apiKey, message, email): p = PushBullet(apiKey) p.pushNote(email, 'EMERGENCY', message, recipient_type='email')
def sendPushBulletNotification(apiKey, message): p = PushBullet(apiKey) devices = p.getDevices() p.pushNote(devices[0]["iden"], 'EMERGENCY', message)
import time from pydub import AudioSegment from pydub.playback import play from pushbullet.pushbullet import PushBullet import os import sys # Script config CERTS_URL = 'https://review-api.udacity.com/api/v1/me/certifications.json' ASSIGN_URL = 'https://review-api.udacity.com/api/v1/projects/{pid}/submissions/assign.json' REVIEW_URL = 'https://review.udacity.com/#!/submissions/{sid}' REQUESTS_PER_SECOND = 1 # Please leave this alone. apiKey = "ENTER YOUR PUSHBULLET API KEY" p = PushBullet(apiKey) # Get a list of devices devices = p.getDevices() # Get a list of contacts contacts = p.getContacts() logging.basicConfig(format = '|%(asctime)s| %(message)s') logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) project = {19:"Pitch Perfect: 15$", 20:"MemeMe 2.0: $33",21:"On the Map: $28",22:"Virtual Tourist:$28",23:"You Decide!: 50$",78:"MemeMe 1.0: $28",95:"Pirate Fleet 1: $15",96:"Robot Maze 2: $15",97:"Alien Adventure 1: $12",98:"Alien Adventure 2: $12",99:"Dry-Run: 35$",101:"Pirate Fleet2: $12",102:"Alien 3: $25",110:"Alien 4: $25",111:"Silly Song: $25",155:"GeoQuiz: $15",168:"Common Interoperability Challenges"} def request_reviews(token): song = AudioSegment.from_mp3("doorbell.mp3") headers = {'Authorization': token, 'Content-Length': '0'}
def sendPushNotification(self): apiKey = "o.BpgNSJ77CGxsWEz2CUJWkDI0oI8hYGoq" p = PushBullet(apiKey) # Getting a list of devices devices = p.getDevices() # Specifying relative path path1 = os.path.realpath(__file__) path2 = os.path.basename(__file__) rel_path = path1.replace(path2, "") # Loading config.json file with open(rel_path + 'config.json', 'r') as f: config_dict = json.load(f) i = 1 while i < 10: deviceList = self.scanDevices() print(deviceList) if devices[0].get("nickname") in deviceList: print("Device found. Sending notification...") print(self.humid) print(self.temp) # Check if the readings are out of range # Send pushbullet notification based on readings status if self.humid < config_dict['min-humidity']: if self.temp < config_dict['min-temperature']: range1 = config_dict['min-humidity'] - self.humid range2 = config_dict['min-temperature'] - self.temp comment = 'The temperature is ' + str(round(range2, 2)) comment = comment + ' degrees lower than the limit ' comment = comment + 'and the humidity is ' comment = comment + str(round(range1, 2)) comment = comment + '% lower than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) elif self.temp > config_dict['max-temperature']: range1 = config_dict['min-humidity'] - self.humid range2 = self.temp - config_dict['max-temperature'] comment = 'The temperature is ' + str(round(range2, 2)) comment = comment + ' degrees higher than the limit ' comment = comment + 'and the humidity is ' comment = comment + str(round(range1, 2)) comment = comment + '% lower than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) else: range = config_dict['min-humidity'] - self.humid comment = 'The humidity is ' + str(round(range, 2)) comment = comment + '% lower than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) elif self.humid > config_dict['max-humidity']: if self.temp < config_dict['min-temperature']: range1 = self.humid - config_dict['max-humidity'] range2 = config_dict['min-temperature'] - self.temp comment = 'The temperature is ' + str(round(range2, 2)) comment = comment + ' degrees lower than the limit ' comment = comment + 'and the humidity is ' comment = comment + str(round(range1, 2)) comment = comment + '% higher than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) elif self.temp > config_dict['max-temperature']: range1 = self.humid - config_dict['max-humidity'] range2 = self.temp - config_dict['max-temperature'] comment = 'The temperature is ' + str(round(range2, 2)) comment = comment + ' degrees higher than the limit ' comment = comment + 'and the humidity is ' comment = comment + str(round(range1, 2)) comment = comment + '% higher than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) else: range = self.humid - config_dict['max-humidity'] comment = 'The humidity is ' + str(round(range, 2)) comment = comment + '% higher than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) elif self.temp < config_dict['min-temperature']: if self.humid < config_dict['min-humidity']: range1 = config_dict['min-humidity'] - self.humid range2 = config_dict['min-temperature'] - self.temp comment = 'The temperature is ' + str(round(range2, 2)) comment = comment + ' degrees lower than the limit ' comment = comment + 'and the humidity is ' comment = comment + str(round(range1, 2)) comment = comment + '% lower than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) elif self.humid > config_dict['max-humidity']: range1 = self.humid - config_dict['max-humidity'] range2 = config_dict['min-temperature'] - self.temp comment = 'The temperature is ' + str(round(range2, 2)) comment = comment + ' degrees lower than the limit ' comment = comment + 'and the humidity is ' comment = comment + str(round(range1, 2)) comment = comment + '% higher than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) else: range = config_dict['min-temperature'] - self.temp comment = 'The temperature is ' + str(round(range, 2)) comment = comment + ' degrees lower than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) elif self.temp > config_dict['max-temperature']: if self.humid < config_dict['min-humidity']: range1 = config_dict['min-humidity'] - self.humid range2 = self.temp - config_dict['max-temperature'] comment = 'The temperature is ' + str(round(range2, 2)) comment = comment + ' degrees higher than the limit ' comment = comment + 'and the humidity is ' comment = comment + str(round(range1, 2)) comment = comment + '% lower than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) elif self.humid > config_dict['max-humidity']: range1 = self.humid - config_dict['max-humidity'] range2 = self.temp - config_dict['max-temperature'] comment = 'The temperature is ' + str(round(range2, 2)) comment = comment + ' degrees higher than the limit ' comment = comment + 'and the humidity is ' comment = comment + str(round(range1, 2)) comment = comment + '% higher than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) else: range = self.temp - config_dict['max-temperature'] comment = 'The temperature is ' + str(round(range, 2)) comment = comment + ' degrees higher than the limit' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) else: comment = 'The temperature is ' + str(round( self.temp, 2)) + ' degrees' comment = comment + ' and the humidity is ' + str( round(self.humid, 2)) comment = comment + '%' p.pushNote(devices[0]["iden"], 'Bluetooth', comment) i = 10 # If the device is not found else: print("Device not found") i = i + 1
# Play on whatever is available first. # print(devices[0]) return devices[0] # exposing api key for now will get new and reset when done client_id = "47b1df84dd804a17a77ddab564c05f79" client_secret = "67681af49c0041959131bad5973529b6" redirect_uri = "http://localhost:8888/callback" pushbullet_api_key = YOUR_KEY_HERE username = "******" scope = "user-read-private user-modify-playback-state user-read-playback-state" # PushBullet SMS module pb = PushBullet(pushbullet_api_key) # Get a list of devices devices = pb.getDevices() print(devices) # authentication # remember to add cache to .gitignore try: token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) except (AttributeError, JSONDecodeError): os.remove(f".cache-{username}") token = util.prompt_for_user_token(username, scope) # create a spotify object
from pushbullet.pushbullet import PushBullet apyKey = "APYKEY" p = PushBullet(apyKey) fileHandle = open ( "resultados.txt", "r") lineList = fileHandle.readlines() fileHandle.close() p.pushNote("*****@*****.**", lineList[-1], "", recipient_type='email') print lineList[-1]