Last active
July 31, 2023 22:19
-
-
Save njh/6757067 to your computer and use it in GitHub Desktop.
Convert the National Trust list of properties into a CSV file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open-uri' | |
require 'csv' | |
require 'json' | |
json = open('https://www.nationaltrust.org.uk/api/search/places?query=&lat=52&lon=0&milesRadius=1000&maxPlaceResults=1000').read | |
CSV.open("nationaltrust.csv", "wb") do |csv| | |
csv << ['id', 'name', 'town', 'county', 'lat', 'long', 'description', 'url'] | |
data = JSON.load(json) | |
data['multiMatch']['results'].each do |place| | |
csv << [ | |
place['id']['value'], | |
place['title'], | |
place['town'], | |
place['county'], | |
place['location']['lat'], | |
place['location']['lon'], | |
place['description'], | |
place['links'][1]['link']['href'], | |
] | |
end | |
end |
Looks like you can search for National Trust properties using:
https://www.nationaltrust.org.uk/api/search/places?query=&lat=52&lon=0&milesRadius=1000&maxPlaceResults=1000
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @njh, I know this is ten years old so I'm curious if you've done something similar with their new website?