Skip to content

Instantly share code, notes, and snippets.

@rantav
Created March 31, 2011 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rantav/896245 to your computer and use it in GitHub Desktop.
Save rantav/896245 to your computer and use it in GitHub Desktop.
Finding the "I'm feeling Ducky" URL for a search term - rails console style
# To run this:
# $ heroku console.
# >> Paste this long line
# condensed in one line for heroku's console; yuk
g = JSON.parse(IO.read('NotableGroceryStores.json')); g['map'].each { |k,v|; puts k; r = Net::HTTP.get 'api.duckduckgo.com', "/?q=#{URI.escape(k)}&o=json"; j = JSON.parse(r); url = nil; url = j['Results'][0]['FirstURL'] if j and j['Results'] and j['Results'][0]; StoreChain.create(:name => k, :url => url) and puts url}
# Run this in rails console:
# this is a json file with all the store names
g = JSON.parse(IO.read('NotableGroceryStores.json'))
g['map'].each do |k,v|
# k has the sore name Just print it for logging
puts k
r = Net::HTTP.get 'api.duckduckgo.com', "/?q=#{URI.escape(k)}&o=json"
j = JSON.parse(r)
url = nil
url = j['Results'][0]['FirstURL'] if j and j['Results'] and j['Results'][0]
# Add to the StoreChain table and print, again for debug
StoreChain.create(:name => k, :url => url)
puts url
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment