Skip to content

Instantly share code, notes, and snippets.

@jamiecobbett
Created November 5, 2012 11:15
Show Gist options
  • Save jamiecobbett/4016699 to your computer and use it in GitHub Desktop.
Save jamiecobbett/4016699 to your computer and use it in GitHub Desktop.
List GOV.UK content slugs by section
require 'json'
require 'open-uri'
require 'cgi'
def subsection_uris
uri = URI.parse("https://contentapi.production.alphagov.co.uk/tags.json?type=section")
json = JSON.parse(uri.open.read)
subsections = json["results"].select do |section_tag|
! section_tag["parent"].nil?
end
subsections.map do |subsection|
subsection["content_with_tag"]["id"]
end
end
subsection_uris.each do |subsection_uri|
begin
uri = URI.parse(subsection_uri)
f = uri.open
json = JSON.parse(f.read)
artefact_slugs = json["results"].map do |artefact|
artefact["web_url"].split("/")[-1]
end
puts ([CGI.unescape(subsection_uri.split("tag=")[-1])] + artefact_slugs).join(",")
rescue OpenURI::HTTPError => e
puts "Encountered #{e.message} for #{uri}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment