def __init__(self, name, price, category): self.name = name self.price = price self.category = category # Default returns id with length 14 and without `:*^`\",.~;%+-'` chars. # Returns id with length 8 and without `A` and `a` letters. self.id = get_unique_id(length=8, excluded_chars="A-z:*^`\",.~;%+-'")
def generate_phones(self): phones_file = open(f"phones_321.txt", "w") random_digits_limit = int( len(self.ph_country_code.strip('+')) + len(self.ph_location_digit)) random_digits_limit = self.ph_digits_limit - random_digits_limit - 1 random_digits = '0' * random_digits_limit start = int('{}{}'.format(self.ph_location_digit, random_digits)) excluded_chars = ":*^`\",.~;%+-'@=#!$%&()/\\|<>?{}[]_asdfghjklqwertyuiopzxcvbnmASDFGHJKLQWERTYUIOPZXCVBNM" phones = [] for ph in range(0, self.total_phones_limit): # start += 1 # phone = "{} {}{}".format(self.ph_country_code, self.ph_location_digit, start) r1 = get_unique_id(length=random_digits_limit, excluded_chars=excluded_chars) phone = "{} {}{}".format(self.ph_country_code, self.ph_location_digit, r1) # r1 = get_unique_id(length=random_digits_limit-3, excluded_chars=excluded_chars) # r2 = get_unique_id(length=3, excluded_chars=excluded_chars) # r2 = self.get_random_num(2) # r3 = self.get_random_digit(end=9) # phone = "{} {}{}{}{}".format(self.ph_country_code, self.ph_location_digit, r1, r2, r3) phones_file.write(phone + '\n') phones.append(phone) print(phone)
def test_max_length(self): for item in range(1000): id_length = randint(1, 128) unique_id = get_unique_id(length=id_length) is_over_length = len(unique_id) != id_length self.assertFalse(is_over_length)
def __init__(self, scenario_name): #Variables self.scenario_name = scenario_name self.scenario_id = get_unique_id(length=8) now = datetime.now() self.creation_date = now.strftime("%d/%m/%Y %H:%M:%S") self.last_accessed = self.creation_date[:] self.exploit_info = ExploitInfo() self.vulnerability_info = VulnerabilityInfo() self.machines = dict()
def download_txt(download_url, book_title, book_directory): response = requests.get(download_url, allow_redirects=True, timeout=5) response.raise_for_status() chech_for_redirect(response) my_id = get_unique_id(6) book_name = sanitize_filename(f'{my_id} - {book_title}.txt') file_path = os.path.join(book_directory, book_name) with open(file_path, 'w') as file: file.write(response.text) return file_path
def download_image(image_url, img_id, img_directory): response = requests.get(image_url, allow_redirects=False, timeout=5) response.raise_for_status() chech_for_redirect(response) extension = img_id[-4:] img_name = sanitize_filename(os.path.join(get_unique_id(6), extension)) file_path = os.path.join(img_directory, img_name) with open(file_path, 'wb') as file: file.write(response.content) return file_path
def test_unique_id(self): unique_ids = list() for item in range(1000): unique_id = get_unique_id() is_duplicated = unique_id in unique_ids self.assertFalse(is_duplicated) unique_ids.append(unique_id)
def test_excluded_chars(self): id_length = 256 excluded_chars = [1, 'f', 'm', 'a', 4, 5, 'Z', 'w', '_'] for item in range(1000): unique_id = get_unique_id(length=id_length, excluded_chars=excluded_chars) for seed in unique_id: is_excluded_char = seed in excluded_chars self.assertFalse(is_excluded_char)
def __init__(self, scenario_name): #Paths self.current_path = Path.cwd() self.scenarios_path = self.current_path / "scenarios" #Fields self.scenario_name = scenario_name self.scenario_id = get_unique_id(length=8) now = datetime.now() self.creation_date = now.strftime("%d/%m/%Y %H:%M:%S") self.last_accessed = self.creation_date[:] self.exploit_info = ExploitInfo("", "", "") self.vulnerability_info = VulnerabilityInfo("", "", "", "") self.machines = dict()
def generate_emails(self): email_file = open("emails_321.txt", "w") excluded_chars = ":*^`\",.~;%+-'@=#!$%&()/\\|<>?{}[]_0123456789" count = 0 for i in range(0, self.total_emails_limit): uni_str = get_unique_id(length=8, excluded_chars=excluded_chars) digits = self.get_random_num(length=3) for dom in self.email_domains: for sym in self.symbols: if count > self.total_emails_limit: return count += 1 # "{custom_letter}{random alphabets}{allowed symbol}{digits}@{domain-name}" email = "{}{}{}{}@{}".format(self.email_custom_text, uni_str, sym, digits, dom).capitalize() email_file.write(email + '\n') more_chars = get_unique_id(length=self.get_random_digit(), excluded_chars=excluded_chars) if sym: # Adt3_sd@ email = "{}{}{}{}{}@{}".format(self.email_custom_text, uni_str, digits, sym, more_chars, dom).capitalize() email_file.write(email + '\n') else: # 1344dfg@ email = "{}{}{}{}@{}".format(self.email_custom_text, uni_str, digits, more_chars, dom).capitalize() email_file.write(email + '\n') print(email)
def save_img(image): directory = "temp/" + get_unique_id( excluded_chars=r'~`!@#$%^&*()_-+=\|]}[{;:"/?.>,<') + ".png" image.save(directory, quality=95) return {"directory": directory}
def get_user_id(): uid = get_unique_id(length=3) return str(uid)
def get_todo_id(): tid = get_unique_id(length=6) return tid
def get_pid(): pid = get_unique_id(length=3) return str(pid)