Skip to content

Instantly share code, notes, and snippets.

@dustMason
Created May 10, 2019 04:17
Show Gist options
  • Save dustMason/07ea0566a0ba4153521cc4d60e90d196 to your computer and use it in GitHub Desktop.
Save dustMason/07ea0566a0ba4153521cc4d60e90d196 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'gpx'
require 'httparty'
require 'pstore'
class Api
include HTTParty
base_uri 'https://atlas-obscura-api.herokuapp.com'
CACHE = PStore.new("cache.pstore")
def all_destinations(offset = 0)
url = "/api/atlas/attractions/United-States?offset=#{offset}"
cached = CACHE.transaction { CACHE[url] }
return cached if cached
response = self.class.get(url)
CACHE.transaction { CACHE[url] = response }
response
end
end
# ele magvar geoidheight name cmt desc src link sym type fix sat hdop vdop pdop ageofdgpsdata dgpsid extensions
class Obscura
def self.go
api = Api.new
gpx = GPX::GPXFile.new
offset = 0
dest = api.all_destinations(offset)
until dest['Attractions'].empty?
puts "found #{dest.size} at offset #{offset}"
dest['Attractions'].each do |stop|
gpx.waypoints << GPX::Waypoint.new({
name: stop["name"],
desc: stop["description"],
lat: stop["coordinates"][0],
lon: stop["coordinates"][1],
link: "https://atlasobscura.com#{stop['path']}"
})
end
offset += dest.size
dest = api.all_destinations(offset)
end
File.open("atlasobscura.gpx", "w") do |f|
f << gpx.to_s
end
end
end
puts Obscura.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment