Created
August 22, 2012 03:50
-
-
Save ttscoff/3422143 to your computer and use it in GitHub Desktop.
Markdown Lucky Link from DuckDuckGo
This file contains hidden or 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
#!/usr/bin/ruby | |
# Where have all the search API's gone, long time passing | |
# Where have all the search API's gone, long time ago | |
# Where have all the search API's gone, gone to graveyards every one | |
# When will they ever learn? | |
# | |
# Inelegantly uses DuckDuckGo's "\" lucky link search and | |
# scrapes the url from the redirect in the result | |
# | |
# $ luckyduck.rb "search term" | |
require 'cgi' | |
query = ARGV[0] | |
res = %x{curl -LSs http://duckduckgo.com/?q=%5C#{CGI.escape(query)}} | |
url = res.match(/window.location.replace\('(.*?)'\)/) | |
print "[#{query}](#{url[1]})" unless url.nil? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment