opencode ergebnis V0.1
This commit is contained in:
1 parent
61d86a3d83
commit
7e498ebc3f
71 files changed
+28982
-46
No files matched your search
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
CSV Import Utils für Straßen
|
||||
"""
|
||||
import csv
|
||||
import io
|
||||
import json
|
||||
|
||||
|
||||
def parse_streets_csv(file_content):
|
||||
"""
|
||||
Parst CSV mit Delimiter ';'
|
||||
Erwartete Spalten: Name, Hausnummer minimal, Hausnummer maximal, Bounding Box
|
||||
"""
|
||||
streets = []
|
||||
# Versuche mit verschiedenen Encodings
|
||||
try:
|
||||
text = file_content.decode('utf-8')
|
||||
except:
|
||||
try:
|
||||
text = file_content.decode('latin-1')
|
||||
except:
|
||||
text = file_content.decode('cp1252')
|
||||
|
||||
f = io.StringIO(text)
|
||||
reader = csv.DictReader(f, delimiter=';')
|
||||
|
||||
for row in reader:
|
||||
name = row.get('Name') or row.get('name') or row.get('Strasse') or row.get('Straße')
|
||||
hn_min = row.get('Hausnummer minimal') or row.get('hn_min') or row.get('Hausnummer_minimal')
|
||||
hn_max = row.get('Hausnummer maximal') or row.get('hn_max') or row.get('Hausnummer_maximal')
|
||||
bbox = row.get('Bounding Box') or row.get('bbox') or row.get('BoundingBox')
|
||||
|
||||
if not name:
|
||||
continue
|
||||
|
||||
try:
|
||||
hn_min_int = int(hn_min) if hn_min and hn_min.strip() else None
|
||||
except:
|
||||
hn_min_int = None
|
||||
|
||||
try:
|
||||
hn_max_int = int(hn_max) if hn_max and hn_max.strip() else None
|
||||
except:
|
||||
hn_max_int = None
|
||||
|
||||
streets.append({
|
||||
'name': name.strip(),
|
||||
'hn_min': hn_min_int,
|
||||
'hn_max': hn_max_int,
|
||||
'bbox': bbox.strip() if bbox else None
|
||||
})
|
||||
|
||||
return streets
|
||||
Reference in new issue
Block a user