-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_data_in_csv.py
48 lines (37 loc) · 1.68 KB
/
fake_data_in_csv.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
import csv
from faker import Faker
from FakedataForData.file_generator.file_factory import build_custom_file_path
from FakedataForData.utils.random_generator import random_number_or_na, random_letter, random_range, true_or_false
def generate_fake_data(with_x_records=5):
"""Generate fake customer data and write to a CSV file."""
fake = Faker('en_GB')
customer_headers = ["Name", "First number", "Second number", "Address", "String", "Another string", "Number", "Boolean",
"Date"]
# Open the file for writing
path_to_file = build_custom_file_path('home/temp/fakeCustomer.csv')
with open(path_to_file, 'w', newline='') as customer_file:
customer_writer = csv.writer(customer_file)
# Write headers
customer_writer.writerow(customer_headers)
# Generate data rows
for count in range(with_x_records):
print(f'count: {count}')
# Generate fake data
name = fake.name()
first_number = random_number_or_na(1)
second_number = random_number_or_na(5)
address = fake.address()
a_string = random_letter(5)
another_string = random_letter(7)
a_number = random_range(0, 5, 3)
a_boolean = true_or_false(5)
a_date = fake.date()
# Write row to CSV
customer_writer.writerow([
name, first_number, second_number, address, a_string,
another_string, a_number, a_boolean, a_date
])
print(f"Generated {with_x_records} fake customer records in fakeCustomer.csv")
# Run the data generation
if __name__ == "__main__":
generate_fake_data(10)