google-list-to-gpx.rb (1929B)
1 #!/usr/bin/env ruby 2 # This script lets you generate a GPX from a Google Maps list. 3 # Steps: 4 # 1. Log in to maps.google.com 5 # 2. Open web console network inspector 6 # 3. Click on whatever list you want 7 # 4. Find the 'getlist' request in the inspector, copy the response body and 8 # paste it as input to this script. 9 require 'time' 10 require 'json' 11 require 'erb' 12 13 content = ARGF.readlines 14 until content.empty? 15 begin 16 data = JSON.parse content.join 17 break 18 rescue JSON::ParserError 19 content.shift 20 end 21 end 22 23 mylist = data.first 24 listname = mylist[4] 25 26 places = mylist[8] 27 28 places = places.reduce([]) do |arr, p| 29 arr << {name: p[2], 30 addr: p[1][4], 31 gps: {lat: p[1][5][2], lon: p[1][5][3]}, 32 desc: p[3], 33 } 34 end 35 36 timenow = Time.now.utc.iso8601 37 header = <<EOF 38 <?xml version='1.0' encoding='UTF-8' standalone='yes' ?> 39 <gpx version="1.1" creator="OsmAnd~ 4.7.10" xmlns="http://www.topografix.com/GPX/1/1" xmlns:osmand="https://osmand.net" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"> 40 <metadata> 41 <name>#{listname}</name> 42 </metadata> 43 EOF 44 45 footer = <<EOF 46 <extensions> 47 <osmand:points_groups> 48 <group name="#{listname}" color="#ab47bc" icon="special_star" background="circle" /> 49 </osmand:points_groups> 50 </extensions> 51 </gpx> 52 EOF 53 54 puts header 55 places.each do |place| 56 puts <<EOF 57 <wpt lat="#{place[:gps][:lat]}" lon="#{place[:gps][:lon]}"> 58 <time>#{timenow}</time> 59 <name>#{place[:name]}</name> 60 <desc>#{place[:desc]}</desc> 61 <type>#{listname}</type> 62 <extensions> 63 <osmand:address>#{place[:addr]}</osmand:address> 64 <osmand:color>#26a69a</osmand:color> 65 <osmand:background>circle</osmand:background> 66 <osmand:icon>special_star</osmand:icon> 67 </extensions> 68 </wpt> 69 EOF 70 end 71 puts footer