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 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_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 handle_command(message): """ Generate profile picture """ user = RandomUser() bot.send_photo(message.chat.id, user.get_picture())