-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_data_dump.py
57 lines (42 loc) · 1.69 KB
/
csv_data_dump.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
# -*- coding: utf-8 -*-
""" Dumping csv file
This script allows the user to dump bunch of synthetically generated csv file to a given directory
This file contains the following function:
* main - the main function of the script
"""
# Built-In functions
import random
import os
def main():
""" Main function to dump csv file """
directory = 'D:\\Profession\\Intern\\Assignments\\Codes\\Assignement Codes\\Part 2\\data_dumps'
path = os.path.join(directory, 'dump_1')
if not (os.path.exists(path)):
os.mkdir(path)
for date in range(1, 31):
# date-month-year
file_name1 = path + '\\' + str(date) + '-8-2020' + '_file1.csv'
# year-month-date
# file_name1 = path + '\\' + '2020-08-' + str(date) + '_file3.csv'
# month_year_date
# file_name1 = path + '\\' + 'Aug_2020_' + str(date) + '_file5.csv'
# date-month-year
file_name2 = path + '\\' + str(date) + '-8-2020' + '_file2.csv'
# year-month-date
# file_name2 = path + '\\' + '2020-08-' + str(date) + '_file4.csv'
# month_year_date
# file_name2 = path + '\\' + 'Aug_2020_' + str(date) + '_file6.csv'
rows = []
for row in range(100):
string = ''
for i in range(10):
if i == 9:
string += str(random.randint(1, 100)) + '\n'
else:
string += str(random.randint(1, 100)) + ','
rows.append(string)
with open(file_name1, 'w') as f1, open(file_name2, 'w') as f2:
f1.writelines(rows)
f2.writelines(rows)
if __name__ == '__main__':
main()