forked from od-ms/converter-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawm-container2023.py
109 lines (85 loc) · 3.17 KB
/
awm-container2023.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# coding=utf-8
import json
import csv
from datetime import datetime
import logging
# Basic logger configuration
logging.basicConfig(level=logging.DEBUG, format='<%(asctime)s %(levelname)s> %(message)s')
LOGGER = logging.getLogger(__name__)
TODAY = datetime.now()
LOGGER.info("=====> START %s <=====", TODAY)
###
### STEP 1: Download data files from AWM website:
### https://awm.stadt-muenster.de/abfuhrtermine-und-entsorgungsstandorte
### a) Choose desired container type
### b) "Bitte den Stadtteil auswählen: 'alle Stadtteile'"
### c) Click on any "Standort"
### d) A map with all positions will show. Check the network requests.
### e) Save response json to this subdirectory "data/"
### f) repeat 3 times (all container types: kleider, elektro, glas)
###
### STEP 2: Run this script
### JSON files will be converted to CSV, CSV-files will be written to "data/" dir
###
path = 'data2023/'
files = [
['awm-glascontainer', 'Glascontainer'],
['awm-altkleider', 'Altkleidercontainer'],
['awm-elektrokleingeraete', 'Elektrokleingeräte-Container']
]
for config in files:
file = config[0]
containertype = config[1]
LOGGER.info("Starting %s / %s", file, containertype)
f = open(path + file + '.json', "r")
myfile = f.read()
data = json.loads(myfile)
geojson = {
"type": "FeatureCollection",
"features": []
}
outfile = path + file + '.csv'
with open(outfile, mode='w') as csv_file:
writer = csv.writer(csv_file, dialect='excel')
writer.writerow(['Nr', 'Containertyp', 'Standort1', 'Standort2', 'Standort3', 'Latitude', 'Longitude', 'Datum'])
# for some reason items is not an array but a dictionary
# print(type(data['poiCategory1']['items']))
counter = 0
for item in data:
counter = counter + 1
if "inf" in item:
LOGGER.info(" %s / %s", counter, item)
writer.writerow([
counter,
containertype,
item['inf'][0],
item['inf'][1],
item['inf'][2],
item['lat'],
item['lng'],
("{}".format(TODAY))[0:10]
])
feature = {
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [float(item['lng']), float(item['lat'])]},
"properties": {
"Typ": containertype,
"Stadtteil": item['inf'][0],
"Standort": item['inf'][1]
}
}
geojson["features"].append(feature)
outfile = path + file + '.geojson'
LOGGER.info("Writing Geojson file '%s' ", outfile)
with open(outfile, mode='w') as json_file:
json.dump(geojson, json_file, indent=2)
# JSON FORMAT
# {
# "inf": [
# "48151 M\u00fcnster - Aaseestadt",
# "Lange Ossenbeck, vor Nr. 9",
# ""],
# "lat": "51.937202",
# "lng": "7.597586"
# }
print("Done")