Skip to content

Instantly share code, notes, and snippets.

@wlib
Last active January 5, 2017 16:26
Show Gist options
  • Save wlib/9f8384732af5090a2b4e5ecbdc2b572c to your computer and use it in GitHub Desktop.
Save wlib/9f8384732af5090a2b4e5ecbdc2b572c to your computer and use it in GitHub Desktop.
Get a website's favicon via duckduckgo
def get(path="/", domain="https://api.duckduckgo.com")
require 'open-uri'
endpoint = "#{domain}/#{path}"
body = open(endpoint).read
return body
end
def get_favicon(page)
favicon = get("/i/#{page}.ico")
require 'digest'
generic_resp = "ad4b0f606e0f8465bc4c4c170b37e1a3"
if Digest::MD5.hexdigest(favicon) == generic_resp
puts "Response is 200-OK, but content is a generic response"
return nil
else
return favicon
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment