-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
54 lines (40 loc) · 1.35 KB
/
run.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
from openpyxl import load_workbook
import json
wb = load_workbook(filename = '20210624.xlsx')
sheet = wb.active
master = {}
master['cities'] = []
data = master['cities']
for row in sheet.iter_rows(min_row=2, max_row=50, max_col=4, values_only=True):
city = row[0]
city = city.rstrip();
district = row[1]
district = district.rstrip();
neighborhood = row[3]
neighborhood = neighborhood.rstrip();
foundCity = False
foundDistrict = False
foundNeighborhood = False
for x in data:
if x['name'] == city:
for y in x['districts']:
if y['name'] == district:
for z in y['neighborhoods']:
if z == neighborhood:
foundNeighborhood = True
if not foundNeighborhood:
y['neighborhoods'].append(neighborhood)
foundDistrict = True
if not foundDistrict:
x['districts'].append({
'name': district,
'neighborhoods': []
})
foundCity = True
if not foundCity:
data.append({
'name': city,
'districts': []
})
with open('output.json', 'w') as outfile:
json.dump(master, outfile)