Skip to content

Instantly share code, notes, and snippets.

@soshial
Created August 13, 2022 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soshial/61e045404bee6013e17edd5a173820c5 to your computer and use it in GitHub Desktop.
Save soshial/61e045404bee6013e17edd5a173820c5 to your computer and use it in GitHub Desktop.
Export lists from Google Maps and import into Organic Maps
import json
if __name__ == "__main__":
c = 0
kml = """<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document><Style id="placemark-red">
<IconStyle>
<Icon>
<href>https://omaps.app/placemarks/placemark-red.png</href>
</Icon>
</IconStyle>
</Style>
<name>ceļojums USA</name>
<visibility>1</visibility>
<ExtendedData xmlns:mwm="https://omaps.app">
<mwm:name>
<mwm:lang code="default">ceļojums USA</mwm:lang>
</mwm:name>
<mwm:annotation>
</mwm:annotation>
<mwm:description>
</mwm:description>
<mwm:lastModified>2022-08-13T13:59:28Z</mwm:lastModified>
<mwm:accessRules>Local</mwm:accessRules>
</ExtendedData>"""
files = ['page1.txt', 'page2.txt', 'page3.txt', 'page4.txt', 'page5.txt', 'page6.txt', 'page7.txt', 'page8.txt', ]
for fileName in files:
with open(fileName, 'r') as f1:
print(fileName)
text_bad = f1.read()
start = text_bad.find("[[\\\"*\\\",")
end = text_bad.find('","e":"')
text_json = text_bad[start:end].replace('\\"', '"').replace('\\\\"', '\\"')
open("tmp.json", 'w').write(text_json)
json_obj = json.loads(text_json)
places_obj = json_obj[0][1]
for place_obj in places_obj:
address_data = place_obj[14][2]
title = place_obj[14][11]
description = place_obj[14][32]
location_data = place_obj[14][72][0][0][8][0]
location = [location_data[2], location_data[1]]
location_text = "%.6f,%.6f" % (location[1],location[0])
place_id = place_obj[14][10]
title_url = title.replace(" ", "+")
c += 1
google_maps_url = f"https://www.google.com/maps/place/{title_url}/data=!4m2!3m1!1s{place_id}"
print(f"{c}. ", title, location, google_maps_url)
kml += f"""<Placemark>
<name>{title}</name>
<description>{description} {google_maps_url}</description>
<TimeStamp><when>2022-08-13T13:59:28Z</when></TimeStamp>
<styleUrl>#placemark-red</styleUrl>
<Point><coordinates>{location_text}</coordinates></Point>
</Placemark>"""
kml += """</Document>
</kml>"""
open("import.kml", "w").write(kml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment