From bfbe5902903f7b17bdb8e4d5a0eba31716497ab2 Mon Sep 17 00:00:00 2001 From: endolith Date: Sun, 23 Oct 2022 13:24:04 -0400 Subject: [PATCH] Add support for Labeled Places.json format Saved Places format: ```json {'geometry': {'coordinates': [...], 'type': 'Point'}, 'properties': {'Google Maps URL': '...', 'Location': {'Address': '...', 'Business Name': '...', 'Country Code': 'US', 'Geo Coordinates': {'Latitude': '...', 'Longitude': '...'}}, 'Published': '2018-05-02T01:46:02Z', 'Title': '...', 'Updated': '2018-05-02T01:46:02Z'}, 'type': 'Feature'} ``` Labeled Places format: ```json {'geometry': {'coordinates': [...], 'type': 'Point'}, 'properties': {'address': '...', 'name': 'Home'}, 'type': 'Feature'} ``` --- json2kml.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/json2kml.py b/json2kml.py index 6bb672c..fb8bd27 100644 --- a/json2kml.py +++ b/json2kml.py @@ -33,17 +33,28 @@ count = 0 for place in data["features"]: if place["type"] == "Feature": - name = html.escape(place["properties"]["Title"]) + try: + name = html.escape(place["properties"]["Title"]) + except KeyError: + name = html.escape(place["properties"]["name"]) print(f'Parsing place "{name}"') - placeLocation = place["properties"]["Location"] lon = place["geometry"]["coordinates"][0] lat = place["geometry"]["coordinates"][1] - if "Address" in placeLocation: - address = html.escape(placeLocation["Address"]) - else: - address = None + try: + placeLocation = place["properties"]["Location"] + + if "Address" in placeLocation: + address = html.escape(placeLocation["Address"]) + else: + address = None + + except KeyError: + if 'address' in place['properties']: + address = html.escape(place['properties']['address']) + else: + address = None kml.newpoint(name=name, coords=[(lon, lat)], address=address) count += 1