Created
March 31, 2011 12:05
-
-
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
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
# 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} |
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
# 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