-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_reader.py
35 lines (25 loc) · 1013 Bytes
/
csv_reader.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
import csv
import pprint
filepath = "/Users/aarondelossantos/Documents/Schedules/Fall 2020.csv"
#filepath = "/Users/aarondelossantos/Desktop/Course Syllabus and Schedule/Reserve Schedule.csv"
# A to Z type of schedule
# possibleSchedTypes = ["A", "B", "C", "D", "E", "F", "G"]
# M to F type of schedule
possibleSchedTypes = ["M", "T", "W", "R", "F"]
def extractData(filepath):
print("Extracting events from CSV file")
try:
csvReader = csv.DictReader(open(filepath,mode='r', encoding='utf-8-sig'))
nestedDict = {}
for schedType in possibleSchedTypes:
nestedDict[schedType] = {}
for counter, row in enumerate(csvReader):
counter = len(nestedDict[dict(row)["Schedule type"]])
nestedDict[dict(row)["Schedule type"]][counter] = dict(row)
except:
print("Unable to import events")
raise
return nestedDict
extractedData = extractData(filepath)
if __name__ == '__main__':
pprint.pprint(extractedData)