-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDataHelper.py
More file actions
24 lines (21 loc) · 864 Bytes
/
Copy pathDataHelper.py
File metadata and controls
24 lines (21 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import xlrd
import re
# Open specified excel file and read data from file.
# Warning: when files are updated and their names get changed, you
# must update the hard coded file name in DataBuilder.py
def dict_builder(path=""):
location = path
book = xlrd.open_workbook(location)
sheet = book.sheet_by_index(0)
sheet.cell_value(0, 0)
data_dictionary = dict()
for rownum in range(1, sheet.nrows):
tempdict = dict()
for cn, values in zip(sheet.row_values(0, 0), sheet.row_values(rownum, 0)):
if (values != ""):
tempdict[cn] = values
if (re.match(r".*Root Table.*", location, re.IGNORECASE)):
data_dictionary[str(sheet.cell_value(rownum, 0))] = tempdict
else:
data_dictionary[str(sheet.cell_value(rownum, 0)).lower()] = tempdict
return data_dictionary