-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstadtwerke.py
50 lines (40 loc) · 1.75 KB
/
stadtwerke.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
# coding=utf-8
import json
import csv
from urllib.request import urlopen
import config as cfg
from pprint import pprint
url = cfg.stadtwerke_url
print("Data url:", url)
f = urlopen(url)
myfile = f.read()
data = json.loads(myfile)
path = 'data/'
def writeEntries(csv_file, category, headlines):
print("Processing " + category)
writer = csv.writer(csv_file, dialect='excel')
writer.writerow(headlines)
# for some reason items is not an array but a dictionary
# print(type(data['poiCategory1']['items']))
for key, item in data[category]['items'].items():
# pprint(item)
if 'center' in item:
writer.writerow([
item['id'],
item['name'],
item['center'][1] if 'center' in item else '',
item['center'][0] if 'center' in item else ''
])
outfile = path + 'haltestellen_barrierefrei.csv'
with open(outfile, mode='w') as csv_file:
writeEntries(csv_file, 'poiCategory1', ['Haltestellen-Id', 'Name der barrierefreien Haltestelle', 'Latitude', 'Longitude'])
outfile = path + 'stadtwerke_bike_and_ride_stationen.csv'
with open(outfile, mode='w') as csv_file:
writeEntries(csv_file, 'poiCategory2', ['Stations-Id', 'Name der Bike-And-Ride-Station', 'Latitude', 'Longitude'])
outfile = path + 'stadtwerke_park_and_ride_stationen.csv'
with open(outfile, mode='w') as csv_file:
writeEntries(csv_file, 'poiCategory3', ['Stations-Id', 'Name der Park-and-Ride-Station', 'Latitude', 'Longitude'])
outfile = path + 'stadtwerke_elektrotankstellen.csv'
with open(outfile, mode='w') as csv_file:
writeEntries(csv_file, 'poiCategory6', ['Id', 'Name der Elektrotankstelle', 'Latitude', 'Longitude'])
print("Done")