Skip to content

Instantly share code, notes, and snippets.

@AlanGabbianelli
Last active August 27, 2020 12:25
Show Gist options
  • Save AlanGabbianelli/28d0ccace14860a817543dfda3f93cbd to your computer and use it in GitHub Desktop.
Save AlanGabbianelli/28d0ccace14860a817543dfda3f93cbd to your computer and use it in GitHub Desktop.
Get list of possible URLs for Settle in the UK smart answer and check that they all return 200
# To run in publisher in production
# $ gds govuk connect app-console -e production publisher
base_url = "https://www.gov.uk/settle-in-the-uk/y"; nil
@edition = SimpleSmartAnswerEdition.published.find_by(slug: "settle-in-the-uk"); nil
@urls = []; nil
def traverse(node, url)
if node.kind == "question"
node.options.each do |option|
@urls << "#{url}/#{option.slug}"
if option.next_node.starts_with?("question")
node = @edition.nodes.find_by(slug: option.next_node)
traverse(node, "#{url}/#{option.slug}")
end
end
end
end
traverse(@edition.nodes.first, base_url); nil
pp @urls.prepend(base_url); nil
require "net/http"
@urls.map do |url|
url = URI.parse(url)
req = Net::HTTP.new(url.host, url.port)
req.use_ssl = true
res = req.request_head(url.path)
res.code
end.all? { |code| code == "200" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment