def get_value(self, key): from model.key import Key from model.keyvaluepair import KeyValuePair try: return KeyValuePair.get((KeyValuePair.key == Key.get_key(key)) & (KeyValuePair.event == self)).value except DoesNotExist: return None
def add(summary, time, tags=[], kvps={}, hash=None, latitude=None, longitude=None, images=[]): result = Event(summary=summary, time=time, latitude=latitude, longitude=longitude, hash=hash) result.save() for tag in tags: result.add_tag(tag) for key in kvps.keys(): db_key = Key.get_key(key) kvp = KeyValuePair(key=db_key, value=kvps[key], event=result) kvp.save(force_insert=True) for image_path in images: image = Image(event=result, file=image_path) image.save()
def __init__(self, buffer): if not isinstance(buffer, Buffer): raise InvalidVideoBuffer() super().__init__(*buffer.size) self.buffer = buffer self.box_container = BoxContainer(*self.buffer.size) self.renders = [self.box_container] self.tmp_renders = [] self.view = True self.fly = Key() self.man_rotate = Key() self.send_commands = Key(True) self.color = (0, 0, 0)
class DroneVision(Canny): def __init__(self, buffer): if not isinstance(buffer, Buffer): raise InvalidVideoBuffer() super().__init__(*buffer.size) self.buffer = buffer self.box_container = BoxContainer(*self.buffer.size) self.renders = [self.box_container] self.tmp_renders = [] self.view = True self.fly = Key() self.man_rotate = Key() self.send_commands = Key(True) self.color = (0, 0, 0) def start(self): self.buffer.start() self.vision_loop() def vision_loop(self): while self.buffer.running(): self.tmp_renders.clear() frame = self.buffer.pop() if frame is not None: self.process_frame(frame) self.hit() if self.get_latest_clusters() is not None: for cluster in self.get_latest_clusters(): self.tmp_renders.append(cluster) self.render_view(frame) def render_view(self, frame): if self.view: self.render(frame) key = show(frame, fps=True, fps_target=10, wait=1, size=(640, 480)) if key == 27: self.kill() self.fly.set(key, 119) # W self.send_commands.set(key, 115) # S self.man_rotate.set(key, 13) # Enter def hit(self): if self.get_center() is not None: self.box_container.hit(self.get_center()) def kill(self): self.buffer.kill() def render(self, image): for element in [self.get_center()] + self.tmp_renders + self.renders: if element is not None: element.render(image, self.color)
def pick_key(chose_id, op): import re global connection global c flag = False c.execute(f'''SELECT category FROM holder WHERE id = '{chose_id}';''') for row in c.fetchall(): row = str(row) row = re.sub(r'[\',)(]', '', row) category = row flag = True c.execute(f'''SELECT serviceName FROM holder WHERE id = '{chose_id}';''') for row in c.fetchall(): row = str(row) row = re.sub(r'[\',)(]', '', row) service = row c.execute(f'''SELECT userName FROM holder WHERE id = '{chose_id}';''') for row in c.fetchall(): row = str(row) row = re.sub(r'[\',)(]', '', row) username = row c.execute(f'''SELECT password FROM holder WHERE id = '{chose_id}';''') for row in c.fetchall(): row = str(row) row = re.sub(r'[\',)(]', '', row) password = row c.execute(f'''SELECT annotations FROM holder WHERE id = '{chose_id}';''') for row in c.fetchall(): row = str(row) row = re.sub(r'[\',)(]', '', row) annotations = row if flag == True: key_temp = Key(chose_id, category, service, username, password, annotations) #SHOW KEY if op == 0: key_temp.show_key() while True: copy = input( ' COPY PASSWORD FOR TRANSFER AREA? [Y/N]:').upper() if copy not in 'YN': print(' INVALID OPTION') elif copy == 'Y': key_temp.copy_password() print(' ******************************') print(' * PASSWORD IN TRANSFER AREA *') print(' * PRESS CTRL+V TO PASTE *') print(' ******************************') break else: print(' ***************************') break #EDIT KEY if op == 1: key_temp.show_key() while True: print(' *******************************') print(' * PRESS ENTER FOR NOT CHANGES *') print(' ******************************') new_category = input(' NEW CATEGORY: ').upper() new_service = input(' NEW SERVICE NAME: ').upper() new_username = input(' NEW USER NAME: ') new_password = input(' NEW PASSWORD: '******' NEW ANNOTATION: ') if new_category == '': new_category = category if new_service == '': new_service = service if new_username == '': new_username = username if new_password == '': new_password = password if new_annotations == '': new_annotations = annotations key_temp = Key(chose_id, new_category, new_service, new_username, new_password, new_annotations) key_temp.show_key() copy = input(' SAVE CHANGES? [Y/N]:').upper() if copy not in 'YN': print(' INVALID OPTION') elif copy == 'Y': key_temp.edit_key(chose_id) print(' ******************************') print(' * CHANGES SAVED *') print(' ******************************') break else: print(' ******************************') print(' * CHANGES NOT SAVED *') print(' ******************************') break #DELETE KEY if op == 2: key_temp.show_key() while True: copy = input(' DELETE KEY? [Y/N]:').upper() if copy not in 'YN': print(' INVALID OPTION') elif copy == 'Y': key_temp.delete_key(chose_id) print(' ******************************') print(f' * KEY ERASE *') print(' ******************************') break else: print(' ******************************') break else: print(' **************************') print(' [!!!] INVALID KEY ID [!!!]') print(' **************************') print()
def generateKey(): now = datetime.datetime.now() hash = hashlib.sha224(unicode(now)).hexdigest() key = Key(passKey = hash, createdAt = now) key.save(); return hash