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)
예제 #2
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))
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)
예제 #4
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
예제 #5
0
파일: bot.py 프로젝트: JohnBox/StarNavi
import random
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')
예제 #6
0
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

df

#All attributes available
#get_cell()