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 SpaceStationNotifier(): __SLEEP__ = 5 def __init__(self): self.Tamara = Tamara() self.hasRun = False self.dailyReload = False self.Tamara.__logger__("SpaceStationNotifier is online") def run(self): while True: now = datetime.datetime.now().time() now_epoch = time.time() if self.dailyReload == False: r = requests.get( 'http://api.open-notify.org/iss-pass.json?lat=-32&lon=116') self.data = json.loads(r.text) self.dailyReload = True if now.hour == 12 and now.minute == 00: self.dailyReload = False # Because you can't see the space station during the day. DUH! if now.hour > 16: for flight in self.data["response"]: flyover_epoch = flight["risetime"] # All epoch times are GMT #print("-------------------------") #print(flyover_epoch) #print(now_epoch) #print("equals") #print(flyover_epoch - now_epoch) #print("--------------------------") #print("--------------------------") if flyover_epoch - now_epoch < 600: if self.prev != flyover_epoch: self.hasRun = False self.prev = flyover_epoch if flyover_epoch - now_epoch < 600 and flyover_epoch - now_epoch > 555: self.Tamara.say( "Ten minutes until space station visible") self.prev = flyover_epoch self.hasRun = True if flyover_epoch - now_epoch < 10 and flyover_epoch - now_epoch > 0 and self.hasRun == True: seconds = int(flyover_epoch - now_epoch) self.Tamara.say( f"{seconds} until international space station flies over" ) time.sleep(self.__SLEEP__)
class GoodMorningAndGoodNight(): def __init__(self): self.Tamara = Tamara() self.status = 1 def main(self): while True: now = datetime.datetime.now() if status == 1: if now.hour == 21 and now.minute == 0: self.Tamara.say("Good. night. s***s", override=True) status = 0 elif now.hour == 9 and now.minute == 0: self.Tamara.say("Good. Morning. Where is my Coffee?", override=True) status = 0 if now.hour == 12 or now.hour == 7: status = 1
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)