-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataUtility.py
49 lines (45 loc) · 1.43 KB
/
dataUtility.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
import csv
import json
def dataByState(data):
new = {}
for item in data:
state = item['City/State']
state = state.strip()
sign = new.get(state, None)
if sign is None:
new[state] = [item]
else:
sign.append(item)
new[state] = sign
return new
def dataByUniq(data):
new = {}
for item in data:
id = item['Unique identifier']
if id is not '':
new[int(id)] = item
return new
def dataByCategory(data):
new = {}
for item in data:
coding = item['Category']
sign = new.get(coding, None)
if sign is None:
new[coding] = [item]
else:
sign.append(item)
new[coding] = sign
return new
with open('data/content.csv') as csvFile:
data = list(csv.DictReader(csvFile))
for item in data:
item.pop('', None)
newData = dataByState(data)
uniqData = dataByUniq(data)
provData = dataByCategory(data)
with open('app/components/utils/rehash.json', 'w') as f:
json.dump(newData, f, ensure_ascii=False, indent = 2, separators=(',', ': '))
with open('app/components/utils/directory.json', 'w') as f:
json.dump(uniqData, f, ensure_ascii=False, indent = 2, separators=(',', ': '))
with open('app/components/utils/provisions.json', 'w') as f:
json.dump(provData, f, ensure_ascii=False, indent = 2, separators=(',', ': '))