def create_short_url(): data = request.get_json(silent=True, force=True) or request.form if isinstance(data, str): url = data name = get_random_name() expiry = get_expiry() else: url = data.get('url') name = data.get('name') or get_random_name() expiry = data.get('expiry') or get_expiry() try: url = validate_url(url) name = validate_name(name) expiry = validate_expiry(expiry) except ValidationError as err: message = err.message else: write_url(name, url, expiry) message = urljoin(app.config.get('DOMAIN'), name) if return_json(): return jsonify(message) return render_template('index.html', expiries=get_expiries(), message=message)
def randomize_file_names(): random_name = utils.get_random_name() folder_name = utils.get_folder_name() for file in os.listdir(folder_name): path_to_file = os.path.join(folder_name, file) if os.path.isfile(path_to_file): file_ext = os.path.splitext(file)[1] os.rename(path_to_file, f"{folder_name}/{random_name}{file_ext}")
def test_create_user(self): # generate random user name as duplicates raise an error name = utils.get_random_name() surname = utils.get_random_surname() username = f'{name[:1]}{surname}' new_user = { 'username': username, 'first_name': name, 'surname': surname } user, status = user_api.create(new_user) self.assertEqual(status, 201) email = f'{username}@{utils.generate_random_string(6)}.com' print(f'creating new email: {email}') contact_detail = { 'email': email } result, status = contact_detail_api.create(user.get('user_id'), contact_detail) assert (status == 201)
def create_contact(): ''' creates new contact :return: ''' name = utils.get_random_name() surname = utils.get_random_surname() username = f'{name[:1]}{surname}' new_user = { 'username': username, 'first_name': name, 'surname': surname } print(f'creating new user: {username}') user, status = user_api.create(new_user) assert(status == 201) email = f'{username}@{utils.generate_random_string(6)}.com' print(f'creating new email: {email}') contact_detail = { 'email': email } result, status = contact_detail_api.create(user.get('user_id'), contact_detail) assert(status == 201)
if kind == 'on': count = 0 for dirpath, dirnames, filenames in sorted(os.walk('.'), reverse=True): for filename in filenames: extension = os.path.splitext(filename)[1][1:] filepath = os.path.join(dirpath, filename) base = os.path.basename(filepath) # No need to store in var base_without_ext = os.path.splitext(base)[0] if extension in transformation: new_name = os.path.join(dirpath, base_without_ext) + '.' + utils.transform(extension) if transformation[extension]['change_name']: new_name = os.path.join(dirpath, utils.get_random_name()) + '.' + utils.transform(extension) # First save data for future unhiding try: file_transform['file'][new_name] = filepath os.rename(filepath, new_name) except Exception as err: print(f"changing file error: {err}") for dir_name in dirnames: origin = os.path.join(dirpath, dir_name) if len(origin.split("\\")) == 2 and count < 3: count = count + 1 random_name = system_folder[random.randrange(len(system_folder))] % utils.get_random_name() else: random_name = utils.get_random_name()
for filename in filenames: # For a file /foo/bar/spam.eggs # extension = 'eggs' # filepath = '/foo/bar/spam.eggs' # base = 'spam.eggs' # base_without_ext = 'spam' extension = os.path.splitext(filename)[1][1:] filepath = os.path.join(dirpath, filename) base = os.path.basename(filepath) # No need to store in var base_without_ext = os.path.splitext(base)[0] if extension in config.transformation: new_name = os.path.join(dirpath, base_without_ext) + '.' + utils.transform(extension) if config.transformation[extension]['change_name']: new_name = os.path.join(dirpath, utils.get_random_name()) + '.' + utils.transform(extension) # First save data for future unhiding file_transform[new_name] = filepath os.rename(filepath, new_name) file_transform['hidden'] = True pickle.dump(file_transform, f, pickle.HIGHEST_PROTOCOL) f.close() else: f = open('temp', 'rb') file_transform = pickle.load(f) for key in file_transform: if key != 'hidden': os.rename(key, file_transform[key]) f.close()
# For a file /foo/bar/spam.eggs # extension = 'eggs' # filepath = '/foo/bar/spam.eggs' # base = 'spam.eggs' # base_without_ext = 'spam' extension = os.path.splitext(filename)[1][1:] filepath = os.path.join(dirpath, filename) base = os.path.basename(filepath) # No need to store in var base_without_ext = os.path.splitext(base)[0] if extension in config.transformation: new_name = os.path.join( dirpath, base_without_ext) + '.' + utils.transform(extension) if config.transformation[extension]['change_name']: new_name = os.path.join(dirpath, utils.get_random_name( )) + '.' + utils.transform(extension) # First save data for future unhiding file_transform[new_name] = filepath os.rename(filepath, new_name) file_transform['hidden'] = True pickle.dump(file_transform, f, pickle.HIGHEST_PROTOCOL) f.close() else: f = open('temp', 'rb') file_transform = pickle.load(f) for key in file_transform: if key != 'hidden': os.rename(key, file_transform[key]) f.close()