def edit(self, job_id: UUID, job: JobData) -> None: try: entity = self.get_collection().find_one({"job_id": job_id.__str__()}) self.fill(job, entity) self.get_collection().find_one_and_update({"job_id": job_id.__str__()}, {"$set": entity}) except Exception as e: raise DataAccessException("Failed to edit job in database!", e)
def get(self, crawler_id: UUID) -> CrawlerDTO: entity = self.get_collection().find_one( {"crawler_id": crawler_id.__str__()}) if entity is None: raise EntityNotFoundException( "Crawler with given id does not exist!") return self.covert(entity)
async def verify_email_by_link(self, link: UUID) -> bool: sql = 'SELECT "email" FROM email_verify_links WHERE link = $1;' async with self.pool.acquire() as con: # type: Connection row = await con.fetchrow(sql, link) if row is None or row["email"] is None or row["email"] == "": logger.debug('Verify ID: "' + link.__str__() + '" was not associated with any email') return False email = row["email"] sql = 'INSERT INTO verified_emails ("email") VALUES ($1);' try: async with self.pool.acquire() as con: # type: Connection await con.execute(sql, email) except Exception as e: logger.error('Failed to insert email "' + email + '" into database table "verified_emails"') logger.error(str(e)) return False logger.debug('E-mail: "' + email + '" was verified') sql = 'DELETE FROM email_verify_links WHERE "email" = $1;' async with self.pool.acquire() as con: # type: Connection await con.execute(sql, email) return True
def validate_uuid4_string(uuid: str): """ Validate that a UUID string is in fact a valid uuid4. Happily, the uuid module does the actual checking for us. It is vital that the 'version' kwarg be passed to the UUID() call, otherwise any 32-character hex string is considered valid. """ lowercase_uuid = uuid.lower() try: val = UUID(lowercase_uuid, version=4) except ValueError: # If it's a value error, then the string # is not a valid hex code for a UUID. return False # If the uuid_string is a valid hex code, # but an invalid uuid4, # the UUID.__init__ will convert it to a # valid uuid4. This is bad for validation purposes. if '-' in uuid: return val.__str__() == lowercase_uuid else: return val.hex == lowercase_uuid
def validate_uuid4(uuid_string): try: val = UUID(uuid_string, version=4) except ValueError: return False return val.__str__() == uuid_string
def get(self, job_id: UUID) -> JobDTO: try: entity = self.get_collection().find_one({"job_id": job_id.__str__()}) except Exception as e: raise DataAccessException("Failed get job from database!", e) if entity is None: raise EntityNotFoundException("Job with id not found!") try: return self.convert(entity) except Exception as e: raise DataAccessException("Failed convert job from database!", e)
async def get_email_by_password_reset_link(self, link: UUID) -> str: sql = 'SELECT "email" FROM password_reset_links WHERE link = $1;' async with self.pool.acquire() as con: # type: Connection row = await con.fetchrow(sql, link) if row is None or row["email"] is None or row["email"] == "": logger.warning("No e-mail found for password reset link: " + link.__str__()) logger.warning("Returning empty string...") return "" return row["email"]
def create_vps(packet_token, packet_project_id, run_id: uuid.UUID): manager = auth_packet(packet_token) device = manager.create_device(project_id=packet_project_id, hostname="benchmark-" + run_id.__str__(), plan="m2.xlarge.x86", facility='ams1', operating_system='centos_8') while True: if manager.get_device(device.id).state == "active": break time.sleep(2) ips = manager.list_device_ips(device.id) return [device.id, ips[0].address]
def getEmployeesWithIDs(): employee_file = os.path.join(DataPath + "/Employees.txt") dict1 = {} with open(employee_file) as my_employee_file: for j, lines in enumerate(my_employee_file): pattern = r'([^a-zA-Z{}0-9-\s])' cleaned = re.sub(pattern,"",lines) cleaned = cleaned.split() #cleaned = re.findall(r'(.*?)(?:[,;\s])',cleaned) if len(cleaned) > 2: if len(cleaned[2])==32 or len(cleaned[2]) == 36 or len(cleaned[2]) == 38: id = UUID(cleaned[2]) name = cleaned[0] + " "+ cleaned[1] dict1[name] = id.__str__() return (dict1)
async def get_qvc_details(cls, wallet_api_key: str, card_id: int, operation_id: UUID) -> Union[dict, bool]: url = QIWIWalletURLS.QIWIMaster.card_details.format(card_id) headers = { "Accept": "application/json", "Authorization": f"Bearer {wallet_api_key}", "Content-Type": "application/json" } json = {"operationId": operation_id.__str__()} try: response = await Connector.request(url=url, headers=headers, json=json, request_type=PUT) response_data = await response.json() except ClientError: logger.warning("Some error. Maybe card_id does not exist.") else: return response_data return False
def deliver_confirmation(id: uuid.UUID): tasks.schedule_confirmation.apply_async((id.__str__(), ))
def guid(self, value: uuid.UUID): if "observers" in self._raw_data: self._raw_data["observers"][0]["guid"] = value.__str__() else: self._raw_data["observers"] = [{"guid": value.__str__()}]
def exists(self, crawler_id: UUID) -> bool: crawler_list = self.get_collection().find( {"crawler_id": crawler_id.__str__()}) return crawler_list.count() > 0
def register_call(self, crawler_id: UUID) -> None: self.get_collection().find_one_and_update( {"crawler_id": crawler_id.__str__()}, {"$set": { "last_call": datetime.now() }})
def delete(self, job_id: UUID) -> None: try: self.get_collection().find_one_and_delete({"job_id": job_id.__str__()}) except Exception as e: raise DataAccessException("Failed to delete job from database!", e)
def deliver_email(id: uuid.UUID): tasks.schedule_email.apply_async((id.__str__(), ))
def get_map_set_import_dir(self, uuid: UUID) -> str: return join(self._config.data_dir, uuid.__str__() + '.import')
def unlock(self, job_id: UUID) -> None: try: self.get_collection().find_one_and_update({"job_id": job_id.__str__()}, {"$set": {"locked": False}}) except Exception as e: raise DataAccessException("Failed to edit job in database!", e)