Skip to content

Instantly share code, notes, and snippets.

@njh
Last active July 31, 2023 22:19
Show Gist options
  • Save njh/6757067 to your computer and use it in GitHub Desktop.
Save njh/6757067 to your computer and use it in GitHub Desktop.
Convert the National Trust list of properties into a CSV file
#!/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
@Shearstock
Copy link

Hey @njh, I know this is ten years old so I'm curious if you've done something similar with their new website?

@njh
Copy link
Author

njh commented Jul 31, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment