forked from anapgh/pycefr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getcsv.py
57 lines (46 loc) · 1.55 KB
/
getcsv.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
#-- PROGRAM TO OBTAIN SUMMARIES FROM CSV
import csv
import os
def create_csv(myDataList):
"""Scrolls through the list looking for different .py files. """
#-- Remove the header
list = myDataList[1:]
myDataCsv = ''
for i in list:
if (myDataCsv == '') or (i[1] != myDataCsv[1][1]):
myDataCsv = [['Repository', 'File Name', 'Class', 'Start Line',
'End Line', 'Displacement', 'Level']]
myDataCsv.append(i)
file_name = myDataCsv[1][1]
write_FileCsv(myDataCsv, file_name)
def write_FileCsv(myDataCsv, file_name, file_csv = ""):
""" Create and add data in the .csv file. """
#-- Get current path
wd = os.getcwd()
#-- Create new folder
try:
os.mkdir(wd + "/DATA_CSV")
except FileExistsError:
pass
file_name = file_name.split('.py')[0] + '.csv'
path_file = wd + '/DATA_CSV/' + file_name
#-- Create a csv with each file name
if not file_csv:
file_csv = open(path_file, 'w')
with file_csv:
writer = csv.writer(file_csv)
writer.writerows(myDataCsv)
else:
with open(path_file, 'a') as f:
writer = csv.writer(f)
writer.writerow(myDataCsv)
def read_FileCsv(file_csv = ""):
""" Read data.csv and create a list to iterate. """
with open('data.csv', newline='') as File:
reader = csv.reader(File)
myDataList = []
for row in reader:
myDataList.append(row)
create_csv(myDataList)
if __name__ == '__main__':
read_FileCsv()