Created
March 2, 2012 03:38
-
-
Save mark-cooper/1955435 to your computer and use it in GitHub Desktop.
Google books embed viewer from isbn code
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
# 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