Пример #1
0
 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
Пример #2
0
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 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 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)
Пример #5
0
 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()))
Пример #6
0
 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()))
Пример #7
0
from randomuser import RandomUser

config = json.load(open('config.json'))

api = lambda url: f'http://localhost:8000/api/{url}'

user_count = 0
users = []
posts = []
while user_count != config['number_of_users']:
    user = RandomUser()
    user_data = {
        'username': user.get_username(),
        'password': user.get_password(),
        'email': user.get_email(),
        'first_name': user.get_first_name(),
        'last_name': user.get_last_name()
    }
    resp = requests.post(api('users/'), json=user_data)
    if resp.status_code == 201:
        user_count += 1
        user_data['id'] = resp.json().get('id')
    else:
        continue
    print('USER CREATED')
    token_data = {'username': user_data['username'], 'password': user_data['password']}
    resp = requests.post(api('token/'), json=token_data)
    if resp.status_code == 200:
        user_data['access'] = resp.json().get('access')
        user_data['refresh'] = resp.json().get('refresh')
        users.append(user_data)
Пример #8
0
import pandas as pd
from randomuser import RandomUser

first = []
last = []
username = []
phone = []
gender = []
email = []

N = 50

for i in range(N):
    user = RandomUser()

    first.append(user.get_first_name())
    last.append(user.get_last_name())
    username.append(user.get_username())
    phone.append(user.get_phone())
    gender.append(user.get_gender())
    email.append(user.get_email())

df = pd.DataFrame(columns=[
    'First_Name', 'Last_Name', 'Gender', 'Username', 'Phone', 'Email'
])
df['First_Name'] = first
df['Last_Name'] = last
df['Gender'] = gender
df['Username'] = username
df['Phone'] = phone
df['Email'] = email
Пример #9
0
 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))