-
Notifications
You must be signed in to change notification settings - Fork 0
/
csvgen.py
77 lines (62 loc) · 2.19 KB
/
csvgen.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
71
72
73
74
75
76
77
import argparse
import secrets
import unicodedata
from textwrap import shorten
import re
import pandas as pd
from faker import Faker
import validators
fake = Faker("fr_FR")
Faker.seed(secrets.randbelow(5000000000000))
def validate_domain(astring):
if not validators.domain(astring):
raise argparse.ArgumentTypeError("Domain name is invalid")
else:
return astring
parser = argparse.ArgumentParser(
description="Generate mock user data for a lab AD session")
parser.add_argument("domain_name", type=validate_domain, nargs=1)
parser.add_argument("root_ou", type=str, nargs=1)
args = parser.parse_args()
DomainName = args.domain_name[0].lower()
RootOU = args.root_ou[0].lower()
space_regex = re.compile(r"\s+", re.UNICODE)
def strip_accents(s):
# Code licensed under CC-BY-SA 3.0 : https://stackoverflow.com/a/518232
return ''.join(c for c in unicodedata.normalize('NFD', s)
if unicodedata.category(c) != 'Mn')
def gen_data():
FirstName = []
LastName = []
EmployeeID = []
UserPrincipalName = []
SamAccountName = []
AccountPassword = []
PostalCode = []
Country = []
for id in range(150):
FirstName.append(space_regex.sub("", strip_accents(fake.first_name())))
LastName.append(space_regex.sub("", strip_accents(fake.last_name())))
EmployeeID.append(id)
UserPrincipalName.append(
f"{FirstName[-1][0].lower()}.{shorten(''.join(filter(str.isalpha, LastName[-1])), width=13, placeholder='').lower()}@{DomainName}"
)
SamAccountName.append(UserPrincipalName[-1].split('@')[0])
AccountPassword.append(secrets.token_urlsafe(32))
PostalCode.append(fake.postcode())
Country.append("FR")
return {
"EmployeeID": EmployeeID,
"FirstName": FirstName,
"LastName": LastName,
"UserPrincipalName": UserPrincipalName,
"SamAccountName": SamAccountName,
"AccountPassword": AccountPassword,
"PostalCode": PostalCode,
"Country": Country
}
if __name__ == '__main__':
data = gen_data()
df = pd.DataFrame(data)
with open("./UserMockList.csv", "w", newline="") as f:
df.to_csv(f, index=False)