-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwd_merge_stations_metadata_csv.py
52 lines (41 loc) · 1.41 KB
/
dwd_merge_stations_metadata_csv.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
#!/usr/bin/env python3
import csv
from glob import glob
from io import TextIOWrapper
from os.path import join
from zipfile import ZipFile
print("merge dwd_stations_metadata")
with open('dwd_stations_metadata.csv', 'w', newline='') as export:
fieldnames = [
'stationid',
'hoehe',
'latitude',
'longitude',
'von',
'bis',
'stationsname'
]
writer = csv.DictWriter(export, fieldnames=fieldnames)
writer.writeheader()
for file in glob("crawler/*.zip"):
print(f"merging {file}")
zipfile = ZipFile(file, 'r')
namelist = zipfile.namelist()
# get relevant meta data
station_geographie_csv = zipfile.open(
next(x for x in namelist if "Metadaten_Geographie_" in x))
csv_reader = csv.DictReader(TextIOWrapper(
station_geographie_csv, 'latin-1'), delimiter=';')
station_list = []
for row in csv_reader:
writer.writerow({
'stationid': row["Stations_id"].strip(),
'hoehe': row["Stationshoehe"].strip(),
'latitude': row["Geogr.Breite"].strip(),
'longitude': row["Geogr.Laenge"].strip(),
'von': row["von_datum"].strip(),
'bis': row["bis_datum"].strip(),
'stationsname': row["Stationsname"].strip(),
})
print("finished press enter to exit...")
input()