Example #1
0
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
Example #3
0
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)
Example #4
0
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)
Example #5
0
    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)
Example #6
0
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)
Example #7
0
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"])
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'}

    logger.info("Requesting certifications...")
Example #9
0
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)
Example #10
0
 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)
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):
            for mydistrictcenters in resp_json:
                if (((mydistrictcenters['pincode'] == 370205)
                     or (mydistrictcenters['pincode'] == 370201))):
                    for availablesessions in mydistrictcenters['sessions']:
                        logger.info(" : Records Fetched")
                        if ((availablesessions['min_age_limit'] == 18) and
                            (availablesessions['available_capacity'] == 0)):
                            currentavailability = False
                        else:
                            currentavailability = True
        else:
            logger.info(" : No rows in the data Extracted from the API")

if (shelf['previousavailability'] != currentavailability):
    shelf['previousavailability'] = currentavailability
    if (currentavailability == True):
        text = 'Vaccine Available'
        body = 'GO GO GO!!!'
    else:
        text = 'Vaccine Unavailable'
        body = 'Go back to sleep'
    p.pushNote(p.getDevices()[0]["iden"], text, body)
shelf.close()
Example #12
0
def notifyuser():
    p = PushBullet(apiKey)
    devices = p.getDevices()
    print(devices)
    p.pushNote(devices[0]["iden"], 'Smart Home Manager', 'Intruder Detected')
Example #13
0
def displayPushBulletDevices(apiKey):
    p = PushBullet(apiKey)
    devices = p.getDevices()
    print(devices)
Example #14
0
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)
Example #15
0
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))
Example #16
0
def sendPushBulletNotification(apiKey, message):
    p = PushBullet(apiKey)
    devices = p.getDevices()
    p.pushNote(devices[0]["iden"], 'EMERGENCY', message)
import datetime
import itertools  #Implements iterators which run efficiently
import json
import requests
from pushbullet.pushbullet import PushBullet
from configparser import ConfigParser
from urllib.parse import urljoin

config = ConfigParser()
config.read("config.ini")
auth = config["push_bullet"]["api_key"]
cowin_api = config["api"]
search_params = config["search"]

p = PushBullet(auth)
push_to_devices = [x["iden"] for x in p.getDevices()
                   if x["active"]]  # allows to push to multiple devices.

numdays = int(search_params["num_days"])  #Converts String into Integer
district_ids = search_params["districts"].split(",")

base = datetime.datetime.today()
date_list = [base + datetime.timedelta(days=x) for x in range(0, numdays, 2)]
date_str = [x.strftime("%d-%m-%Y") for x in date_list]

header = {
    'User-Agent':
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) "
    "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"
}
Example #18
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