Skip to content

Instantly share code, notes, and snippets.

@waynegraham
Created October 27, 2010 17:03
Show Gist options
  • Save waynegraham/649460 to your computer and use it in GitHub Desktop.
Save waynegraham/649460 to your computer and use it in GitHub Desktop.
require 'open3'
require 'open-uri'
require 'rubygems'
require 'nokogiri'
def read_results(query, max_results = 2)
results = open "http://search.lib.virginia.edu/catalog?q=#{URI.escape(query)}&per_page=#{max_results}"
Open3.popen3('say -v Vicki') do |stdin, stdout, stderr|
stdin << "Virgo results for #{query}...using reusable code"
Nokogiri::XML(results).search('.document').each_with_index do |d,i|
stdin << "Item #{i+1},"
stdin << "Catalog key, #{d['id'].gsub(/^Doc/,'')},"
stdin << "Title, #{d.at('.titleField a').text},"
end
stdin.close
end
end
read_results('rocket science', 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment