-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_generator.py
70 lines (57 loc) · 1.55 KB
/
user_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
from faker import Faker
import hashlib
import random
def get_hash(password):
"""
hashlib.sha256(password).hexdigest()
"""
return hashlib.sha256(password.encode('utf-8')).hexdigest()
def to_sql(s):
return '\'' + s.replace("'" , "''") + '\''
def get_institution():
return random.randrange(2,8573)
def get_country():
return random.randrange(2,197)
def get_rating():
return random.randrange(100 , 2500)
def rearrange_str(s):
x =list(s)
random.shuffle(x)
return ''.join(x)
def rearrange_mail(mail):
x = mail.split('@')
return rearrange_str(x[0] ) + '@' + x[1]
def main():
fil = open('gen.sql',mode='w')
fake = Faker()
n=int(input('total user:'))
for _ in range(n):
profile = fake.profile()
#print(profile['username'])
#print(profile['mail'])
#print(to_sql(profile['name']))
sql =f"""insert into oj.users(user_id ,
handle ,
user_name ,
email ,
rating ,
PASSWORD_HASH,
COUNTRY_ID ,
INSTITUTION_ID )
values(oj.user_id_seq.nextval ,
{to_sql(rearrange_str(profile['username'])) } ,
{to_sql(profile['name']) } ,
{to_sql(rearrange_mail(profile['mail'])) } ,
{get_rating()} ,
{to_sql(get_hash('123'))} ,
{get_country()},
{get_institution()}
);"""
print(sql , file= fil)
if __name__ == '__main__':
main()