Last active
January 5, 2017 16:26
-
-
Save wlib/9f8384732af5090a2b4e5ecbdc2b572c to your computer and use it in GitHub Desktop.
Get a website's favicon via duckduckgo
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
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