Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
Created March 2, 2012 03:38
Show Gist options
  • Save mark-cooper/1955435 to your computer and use it in GitHub Desktop.
Save mark-cooper/1955435 to your computer and use it in GitHub Desktop.
Google books embed viewer from isbn code
# find isbn numbers with at least partial Google books embed viewer
require 'nokogiri'
require 'open-uri'
require 'json'
# load a with ISBN numbers
a = []
g = 'http://books.google.com/books?jscmd=viewapi&bibkeys='
# editions results is a .csv file containing ISBN data
File.open('editions_results.csv').each_line do |line|
d = line.split("\t")
a << d[7]
end
a.delete 0 # .csv file contains header
a.each do |v|
v = v.split("|")[0] if v =~ /\|/ # multiple isbns may be '|' delimited, use 1st
next if v.empty?
doc = Nokogiri::HTML(open(g + v))
doc.css('p').each do |p|
c = p.content
/\{.*\}/.match(c) do |m|
j = JSON.parse(m[0])
if j[v] and j[v].has_key? 'preview' and j[v]['preview'] != 'noview'
puts v
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment