class BongOn(): __SLEEP__ = 30 def __init__(self): self.tamara = Tamara() # Why does this require [0]??? self.modules = self.tamara.load_db(table='modules') self.modules = self.tamara.ret_row(self.modules, 'fourtwenty') print(self.modules) self.status = self.modules[self.tamara.find_index("status")] def main(self): while True: now = datetime.datetime.now() print(self.status) if now.hour == 16 and now.minute == 20: if (self.status == 0): self.tamara.say("Happy 420") self.tamara.save(user="******", where="module", table="public.modules", status=1) if now.hour == 12: self.tamara.save(user="******", where="module", table="public.modules", switch=0) time.sleep(self.__SLEEP__)
class FaceDetection(): def __init__(self): self.Tamara = Tamara() self.users = self.Tamara.load_db() self.online_users = self.Tamara.online() self.video_capture = cv2.VideoCapture(0) self.me_image = face_recognition.load_image_file("me.jpg") self.me_face_encoding = face_recognition.face_encodings( self.me_image)[0] def main(self): while True: #print(self.Tamara.online()) # Grab a single frame of video ret, frame = self.video_capture.read() # Resize frame of video to 1/4 size for faster face recognition processing small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) face_locations = face_recognition.face_locations(small_frame) face_encodings = face_recognition.face_encodings( small_frame, face_locations) face_names = [] for face_encoding in face_encodings: # See if the face is a match for the known face(s) match = face_recognition.compare_faces([self.me_face_encoding], face_encoding) name = "Unknown" if match[0]: self.Tamara.say("Hello Aaron") else: print("Not the former president") # Release handle to the webcam self.video_capture.release() cv2.destroyAllWindows()
class Home(): """ This class detects who has connected to the wifi. It has no params. The only data it uses include - User - Mac - Status - Filename (File) - Saying It has write properties to the db - Status """ __SLEEP__ = 5 __PERIOD__ = 600 def __init__(self): self.Tamara = Tamara() self.Tamara.__logger__("Am I Home?") self.users = self.Tamara.load_db() #returns list self.beginningoftime = datetime.datetime(2017, 1, 1, 0, 0, 0) def main(self): """ Main function. Loops run forever """ while True: # How fast is the call to the db? self.users = self.Tamara.load_db() #print(self.users) # How long does this function take? self.run() time.sleep(self.__SLEEP__) # #def find_index(self, column): # index = [i for i,x in enumerate(self.Tamara.db_vars) if x == column] # print(index[0]) # return index[0] def run(self): """ Search for users and commits actions # TO DO. - Put in own thread?? """ p = subprocess.Popen("arp-scan -l", stdout=subprocess.PIPE, shell=True) (output, err) = p.communicate() p_status = p.wait() for i, users in enumerate(self.users): user = users[self.Tamara.find_index("users")] mac = users[self.Tamara.find_index("mac")].lower() status = int(users[self.Tamara.find_index("status")]) finish = users[self.Tamara.find_index("finish")] start = users[self.Tamara.find_index("start")] session = users[self.Tamara.find_index("session")] nsession = users[self.Tamara.find_index("nsession")] speech = users[self.Tamara.find_index("EntrySpeech")] media = users[self.Tamara.find_index("media")] now = datetime.datetime.now() # If online and previous status offline if mac in output.decode("utf-8") and status == 0: secondsOffline = (now - finish).total_seconds() self.Tamara.__logger__( f"home {user}: Offline total seconds: {secondsOffline}") if (now - finish).total_seconds() > self.__PERIOD__: self.action(self.users[i], media, speech) nsession += 1 self.Tamara.save(user=user, status=1, start=now, nsession=(nsession)) #Update database elif mac in output.decode("utf-8"): self.Tamara.save(user=user, status=2, session=((now - start).total_seconds())) #update status in database to 2 elif not mac in output.decode("utf-8") and status > 0: self.Tamara.save(user=user, status=0, finish=now) def action(self, user, media, speech): self.Tamara.__logger__(f"{user}, {media}, {speech}") time.sleep(30) if media is not None: self.Tamara.play(media) print(media) else: print(media) if speech is not None: self.Tamara.say(speech) print(speech) else: print(speech)