def random_user_exists(mycursor): user = RandomUser() user_id = find_one_by_email(mycursor, user.get_email()) if not user_id: create_account(mycursor, user) loaded = find_one_by_email(mycursor, user.get_email()) create_address(mycursor, user, loaded)
def generate_random_participant(): """Generates a random participant using randomuser package""" user = RandomUser({'nat': 'us'}) participant = Participant(firstname=user.get_first_name(), lastname=user.get_last_name(), number_of_trials=randint(1,3), matriculation=randint(300000, 500000)) return participant
def get_user_columns(id): cols = [] user = RandomUser() cols.append(id) cols.append(user.get_first_name()) cols.append(user.get_last_name()) cols.append('{} {}, {} {}'.format(user.get_street(), user.get_city(), user.get_state(), str(user.get_zipcode()))) cols.append(user.get_email()) cols.append(user.get_password()) return cols
def handle_command(message): """ Generate full user profile """ user = RandomUser() bot.send_photo(message.chat.id, user.get_picture()) bot.send_message( message.chat.id, f""" <b>Full Name:</b> {user.get_full_name()} <b>DoB:</b> {user.get_dob()[:10]} <b>Address:</b> <i>{user.get_street()}, {user.get_city()} {user.get_zipcode()} {user.get_state()}, {user.get_country()}</i> """)
def insertPolicy(total): # Generate a list of 10 random users user_list = RandomUser.generate_users(total, {'nat': 'us'}) for i in range(total): serial_no = list('0123456789') random.shuffle(serial_no) serial_no = int(''.join(serial_no[:8])) place_from = "Beijing" if random.randint(0, 1) else "Dublin" place_to = "Dublin" if place_from is "Beijing" else "Beijing" policy_type = "Single" if random.randint(0, 1) else "Return" validate_from = datetime(2019, random.randint(1, 12), random.randint(1, 15), random.randint(0, 23), random.randint(0, 59)) validate_to = validate_from + timedelta(days=random.randint(1, 3)) customer_id = random.randint(51, 100) temp = list('0123456789') random.shuffle(temp) flight_no = "BD" + ''.join( temp[:6]) if place_from is "Beijing" else "DB" + ''.join(temp[:6]) policy_holder = user_list[i].get_first_name( ) + " " + user_list[i].get_last_name() insurance_type = "Luggage Lost" pieces_of_luggage = random.randint(1, 10) print(serial_no, place_from, place_to, validate_from, validate_to, customer_id, flight_no, policy_holder, insurance_type, pieces_of_luggage) sql = "INSERT INTO policy (serial_no, place_from,place_to,policy_type,validate_from,validate_to,customer_id," \ "flight_no,policy_holder,insurance_type,pieces_of_luggage,is_claimed) VALUES ('%d', '%s','%s','%s','%s','%s','%d','%s'," \ "'%s','%s','%d','%d')" % (serial_no, place_from, place_to, policy_type, validate_from, validate_to, customer_id, flight_no, policy_holder, insurance_type, pieces_of_luggage, 0) cursor.execute(sql) connection.commit() connection.close()
def insertUser(total): user_list = RandomUser.generate_users(total, {'nat': 'us'}) headers = { "Host": "localhost", "Content-Type": "application/x-www-form-urlencoded", "Referer": "http://localhost:8080", # 必须带这个参数,不然会报错 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36", } url = "http://localhost:8080/result" password = "******" for i in range(total): form_data = { "password": password, "passwordCheck": password, "emailAddress": user_list[i].get_email(), "lastName": user_list[i].get_last_name(), "firstName": user_list[i].get_first_name(), "passport": user_list[i].get_id_number(), "phoneNumber": user_list[i].get_phone(), "nickname": user_list[i].get_username(), "role": random.randint(1, 2) } results = requests.post(url, data=form_data, headers=headers).text
def _get_random_users(qty: int = 1000): while True: try: return RandomUser.generate_users(qty, get_params=dict(nat='GB')) except Exception: print('Sleeping 1 sec and trying again') time.sleep(1)
def gen_hundred_users(): user_list = RandomUser.generate_users(100, {'gender': 'male'}) formatted_users = [] for user in user_list: formatted_user = (user.get_first_name(), user.get_last_name(), user.get_age(), user.get_gender(), user.get_email()) formatted_users.append(formatted_user) return formatted_users
def create_random_person_data(how_many: int) -> List[PersonData]: # import is in function because circular import from .DataDeserializer import DataDeserializer users = RandomUser.generate_users(how_many) users_data = [user._data for user in users] return DataDeserializer.deserialize_many(users_data)
def handle_command(message): """ Generate address """ user = RandomUser() bot.send_message( message.chat.id, f""" {user.get_street()}, {user.get_city()} {user.get_zipcode()} {user.get_state()}, {user.get_country()} """)
def generateUsers(n): from randomuser import RandomUser users = {"abc": "123"} temp = RandomUser.generate_users(5) for user in temp: users[user.get_username()] = user.get_password() with open('users.json', 'w') as outfile: json.dump(users, outfile, indent=2)
def generate_sponsor(i): exists = True while exists: print(f"Generating Random Sponsor {i}") random_user = RandomUser({'nat': 'us', 'gender': 'male'}) name = " ".join(random_user.get_street().split()[1:-1]) name += " Auto Parts" exists = Sponsor.query.filter_by(name=name).first() random_picture = requests.get(random_user.get_picture()) random_name = secrets.token_hex(8) _, extension = os.path.splitext(random_user.get_picture()) file_name = random_name + extension path = os.path.join(app.root_path, "static/profile_pictures", file_name) size = 500, 500 picture = Image.open(BytesIO(random_picture.content)) picture.thumbnail(size) picture.save(path) sponsor = Sponsor(name=name, picture=file_name) catalog = Catalog(sponsor=sponsor) db.session.add(sponsor) db.session.add(catalog)
def handle(self, *args, **options): user_list = RandomUser.generate_users(options['count']) for i in user_list: user = User() user.username = i.get_username() user.first_name = i.get_first_name() user.last_name = i.get_last_name() user.email = i.get_email() user.password = i.get_password() user.date_joined = datetime.now(tz=timezone.utc) user.save() self.stdout.write(self.style.SUCCESS(f'successfully published '))
def create_order_address(mycursor): user = RandomUser() sql = ''' INSERT INTO `ecommerce_address` (`first_name`, `last_name`, `phone_number`, `street`, `city`, `postcode`, `created_at`, `updated_at`, `country_code`, `province_code`, `province_name`) VALUES (%s, %s, %s, %s, %s, %s, now(), now(), 'PT', NULL, NULL); ''' args = (user.get_first_name(), user.get_last_name(), user.get_phone(), user.get_street(), user.get_city(), user.get_postcode()) mycursor.execute(sql, args) return mycursor.lastrowid
def handle(self, *args, **kwargs): total = kwargs['total'] for i in range(total): user = RandomUser() User.objects.create_user(username=RandomUser.get_username(user), first_name=RandomUser.get_first_name(user), last_name=RandomUser.get_last_name(user), email=RandomUser.get_email(user), password=RandomUser.get_password(user), date_joined=RandomUser.get_registered(user))
def random_users(): db.drop_all() db.create_all(app=app) users = RandomUser.generate_users(100, {'gender': 'male'}) for user in users: user = UserModel(first_name=user.get_first_name(), last_name=user.get_last_name(), dob=user.get_dob(), gender=user.get_gender() # may add more fields(city, number ...) ) db.session.add(user) db.session.commit() return app
def insertPolicyAndClaim(total): print("insertPolicyAndClaim") # Generate a list of total random users user_list = RandomUser.generate_users(total, {'nat': 'us'}) for i in range(total): serial_no = list('0123456789') random.shuffle(serial_no) serial_no = int(''.join(serial_no[:8])) place_from = "Beijing" if random.randint(0, 1) else "Dublin" place_to = "Dublin" if place_from is "Beijing" else "Beijing" policy_type = "Single" if random.randint(0, 1) else "Return" validate_from = datetime(2019, random.randint(1, 4), random.randint(1, 25), random.randint(0, 23), random.randint(0, 59)) validate_to = validate_from + timedelta(days=random.randint(1, 3)) customer_id = random.randint(51, 100) temp = list('0123456789') random.shuffle(temp) flight_no = "BD" + ''.join( temp[:6]) if place_from is "Beijing" else "DB" + ''.join(temp[:6]) policy_holder = user_list[i].get_first_name( ) + " " + user_list[i].get_last_name() insurance_type = "Luggage Lost" pieces_of_luggage = random.randint(1, 10) if random.randint(0, 1): employee_id = random.randint(1, 50) result = "Approved" if random.randint(0, 1) else "Rejected" else: employee_id = 0 result = "Unprocessed" print(serial_no, place_from, place_to, validate_from, validate_to, customer_id, flight_no, policy_holder, insurance_type, pieces_of_luggage) sql = "INSERT INTO policy (serial_no, place_from,place_to,policy_type,validate_from,validate_to,customer_id," \ "flight_no,policy_holder,insurance_type,pieces_of_luggage,is_claimed) VALUES ('%d', '%s','%s','%s','%s','%s','%d','%s'," \ "'%s','%s','%d','%d')" % (serial_no, place_from, place_to, policy_type, validate_from, validate_to, customer_id, flight_no, policy_holder, insurance_type, pieces_of_luggage, 1) cursor.execute(sql) print(serial_no, user_list[i].get_street() + " " + user_list[i].get_city(), customer_id, validate_from, str(user_list[i].get_picture()), 0, flight_no) sql = "INSERT INTO claim (serial_no, billing_address, customer_id, submit_date, details, employee_id, flight_no, result" \ ") VALUES ('%d','%s', '%d', '%s', '%s', '%d', '%s', '%s')" % \ (serial_no, user_list[i].get_street() + " " + user_list[i].get_city(), customer_id, validate_from, str(user_list[i].get_picture()), employee_id, flight_no, result) cursor.execute(sql) connection.commit() connection.close()
def generate_fake_providers(num_customers: int = 10): def generate_address(user): street = user.get_street() city = user.get_city() state = user.get_state() address = ','.join([street, city, state]) return address user_list = RandomUser.generate_users(10) user_list = list( map( lambda x: dict(first_name=x.get_first_name(), last_name=x.get_last_name(), email=x.get_email(), address=generate_address(x), pincode=x.get_zipcode(), cellphone=x.get_cell()), user_list)) return user_list
def generate_user(i, user_type): exists = True while exists: print(f"Generating Random {user_type} {i}") random_user = RandomUser({'nat': 'us', 'gender': 'male'}) exists = User.query.filter_by(email=random_user.get_email()).first() random_picture = requests.get(random_user.get_picture()) random_name = secrets.token_hex(8) _, extension = os.path.splitext(random_user.get_picture()) file_name = random_name + extension path = os.path.join(app.root_path, "static/profile_pictures", file_name) size = 500, 500 picture = Image.open(BytesIO(random_picture.content)) picture.thumbnail(size) picture.save(path) password = bcrypt.generate_password_hash("password").decode("utf-8") user = User(user_type=user_type, first_name=random_user.get_first_name(), last_name=random_user.get_last_name(), email=random_user.get_email(), password=password, picture=file_name) if user_type == UserTypes.DRIVER: for j in range(0, randint(0, MAX_SPONSORSHIPS)): exists = True while exists: print(f"Generating Random Sponsorship {j} for Random User {i}") sponsor_id = randint(1, Sponsor.query.count()) sponsor = Sponsor.query.get(sponsor_id) exists = sponsor in user.all_sponsors() sponsorship = Sponsorship() sponsorship.driver = user sponsorship.sponsor = sponsor sponsorship.active = bool(getrandbits(1)) if sponsorship.active: sponsorship.points = randint(0, MAX_POINTS) db.session.add(sponsorship) elif user_type == UserTypes.STORE_MANAGER: sponsor_id = randint(1, Sponsor.query.count()) user.employer = Sponsor.query.get(sponsor_id) db.session.add(user)
def load_rows(rows: int): """ loading db data when starting app """ initialize_db() for user in RandomUser.generate_users(rows): # gallery loads img_file = open(f"static/img/users/{user.get_first_name()}.jpg", "wb") img_file.write(requests.get(user.get_picture().format()).content) img_file.close() # db data loads User.create( first_name=user.get_first_name(), last_name=user.get_last_name(), gender=user.get_gender(), phone=user.get_phone(), email=user.get_email(), state=user.get_state(), ).save()
def getAverage(subjects): avg = 0 for subject in subjects: avg = (avg + subject['avgRating']) / 2 return avg if __name__ == "__main__": db = initFirestore() collection_name = "users" # Write a test of 10 (American) users to Firestore database numUsers = 20 users = RandomUser.generate_users(numUsers, {"nat": "us"}) print(f"[INFO]: Adding {numUsers} to Firestore database...") for user in tqdm(users): userData = parseUser(user) # For now, just use the email for Document IDs doc_ref = db.collection(collection_name).document(user.get_email()) doc_ref.set(userData) subjects = [] # Add 3 random subjects to proficientStudies sub-collection for subject in userData['proficientStudies']: subject_ref = doc_ref.collection("proficientStudies").document( subject) subject = parseSubject(subject) subject_ref.set(subject)
from randomuser import RandomUser from python_graphql_client import GraphqlClient import ssl try: _create_unverified_https_context = ssl._create_unverified_context except AttributeError: pass else: ssl._create_default_https_context = _create_unverified_https_context randomUser = [] user_list = RandomUser.generate_users(10, {'nat': 'de'}) for user in user_list: randomUserProperties = {} randomUserProperties["first_name"] = user.get_first_name() randomUserProperties["last_name"] = user.get_last_name() randomUserProperties["phone_number"] = user.get_phone() randomUserProperties["street"] = user.get_street() randomUserProperties["zip_code"] = user.get_zipcode() randomUserProperties["city"] = user.get_city() randomUser.append(randomUserProperties) client = GraphqlClient( endpoint='http://95.217.162.167:8080/v1/graphql') variables = {"first_name": randomUserProperties["first_name"], "last_name": randomUserProperties["last_name"], "phone_number": randomUserProperties["phone_number"], "street": randomUserProperties["street"], "zip_code": randomUserProperties["zip_code"], "city": randomUserProperties["city"]} insertQuery = """
def create_random(cls): user = RandomUser() name = user.get_username() return Team(name=name, enabled=True)
from datetime import datetime d1 = datetime.strptime('1/1/2018 1:30 PM', '%m/%d/%Y %I:%M %p') d2 = datetime.strptime('1/1/2021 4:50 AM', '%m/%d/%Y %I:%M %p') !pip install bcrypt from randomuser import RandomUser import hashlib import bcrypt from passlib.hash import sha512_crypt # Generate a single user user = RandomUser() class Car_Owner: username="" email="" phone="" password="" points=0 price_to_pay=0 hashed_password ="" sessionID =0 class Energy_Supplier: id="" company_name=""
def _add_user_to_optimized_phonebook(self, user: RandomUser): self._optimized_phonebook.add_person( Person(first_name=user.get_first_name(), last_name=user.get_last_name(), city=user.get_city(), phone=user.get_phone()))
def _add_user_to_simple_phonebook(self, user: RandomUser): self._simple_phonebook.add_person( dict(first_name=user.get_first_name(), last_name=user.get_last_name(), phone=user.get_phone(), city=user.get_city()))
def handle_command(message): """ Generate full name """ user = RandomUser() bot.send_message(message.chat.id, user.get_full_name())
def handle_command(message): """ Generate date of birth """ user = RandomUser() bot.send_message(message.chat.id, user.get_dob()[:10])
def get_random_users(count=100): return RandomUser.generate_users(count)
def handle_command(message): """ Generate profile picture """ user = RandomUser() bot.send_photo(message.chat.id, user.get_picture())