-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_users.py
More file actions
61 lines (52 loc) · 2.33 KB
/
Copy pathgenerate_users.py
File metadata and controls
61 lines (52 loc) · 2.33 KB
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
import csv
import uuid
from faker import Faker
from random import randint, choice
from datetime import datetime, timedelta
faker = Faker()
departments = [1, 2, 3, 5] # Example department IDs
job_titles = ['Software Developer', 'Data Analyst', 'HR Officer', ' Assistant', 'Intern']
genders = ['Male', 'Female']
duty_stations = ['Head Office', 'Lilongwe Branch', 'Blantyre Branch', 'Mzuzu Branch']
def random_date(start, end):
return faker.date_between(start_date=start, end_date=end)
def generate_username(first_name, last_name, existing_usernames):
base = f"{first_name.lower()}{last_name.lower()}"
username = base
counter = 1
while username in existing_usernames:
username = f"{base}{counter}"
counter += 1
existing_usernames.add(username)
return username
with open("userrs.csv", "w", newline='') as file:
writer = csv.writer(file)
writer.writerow([
"Id", "UserName", "NormalizedUserName", "Email", "NormalizedEmail",
"EmailConfirmed", "PasswordHash", "SecurityStamp", "ConcurrencyStamp",
"PhoneNumber", "PhoneNumberConfirmed", "TwoFactorEnabled", "LockoutEnd",
"LockoutEnabled", "AccessFailedCount", "FirstName", "JobTitle", "LastName",
"DepartmentId", "DateOfBirth", "EmployeeImage", "Gender", "Nationality",
"StartDate", "DutyStation", "Status"
])
used_usernames = set()
for _ in range(400):
first = faker.first_name()
last = faker.last_name()
username = generate_username(first, last, used_usernames)
normalized_username = username.upper()
email = f"{username}@example.com"
user_id = str(uuid.uuid4())
dob = random_date("-45y", "-20y")
start_date = random_date("-5y", "today")
lockout_end = (datetime.now() + timedelta(days=randint(0, 30))).date() if randint(0, 1) else ''
gender = choice(genders)
writer.writerow([
user_id, username, normalized_username, email, email.upper(),
1, faker.sha256(), str(uuid.uuid4()), str(uuid.uuid4()),
faker.msisdn()[0:10], 1, 0, lockout_end,
0, 0, first, choice(job_titles), last,
choice(departments), dob, '', gender, 'Malawian',
start_date, choice(duty_stations), 1
])
print("✅ CSV with 400 clean users (no numbers in usernames) generated as 'users.csv'.")