-
Notifications
You must be signed in to change notification settings - Fork 0
/
generators.py
70 lines (59 loc) · 1.56 KB
/
generators.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
"""
Dummy csv generator
"""
import unidecode
from random import randint, choice
EMAIL_DOMAINS = [
(60, 'gmail.com'),
(90, 'hotmail.com'),
(100, 'mailinator.com')
]
EMAIL_TEMPLATES = [
'{name}{lastname[0]}@{domain}',
'{name[0]}{lastname}@{domain}',
'{name}{lastname}@{domain}',
'{name}.{lastname}@{domain}',
'{name}{number}@{domain}',
'{lastname[0]}{name}{number}@{domain}',
]
def add_new_column(header, rows, column_name, column_generator):
"""
Add new column with generator
"""
updated_rows = []
for row in rows:
mutable_row = list(row)
mutable_row.append(column_generator(row))
updated_rows.append(mutable_row)
mutable_header = list(header)
mutable_header.append(column_name)
return mutable_header, updated_rows
def get_random_email_domain():
"""
Return random email domain
"""
random = randint(0, 100)
for domain in EMAIL_DOMAINS:
if random <= domain[0]:
return domain[1]
return None
def get_random_mail_template():
"""
Return random mail template
"""
return choice(EMAIL_TEMPLATES)
def email_generator(row):
"""
Email generator
"""
[name, lastname, *_] = row
template = get_random_mail_template()
mail = template.format(
name=name,
number=randint(1, 1000),
lastname=lastname,
domain=get_random_email_domain()
)
mail_without_simbols = mail.lower().replace(" ", "")
mail_unaccent = unidecode.unidecode(mail_without_simbols)
return mail_unaccent