Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fetching info from Amazon, Flipkart, Bookseer link

  • Loading branch information...
commit de64bac971300609e58a20066f4f736a92b9e535 1 parent bfdf7f4
@swaroopch authored
View
67 app/models/amazon_info.rb
@@ -0,0 +1,67 @@
+#!/usr/bin/env ruby
+
+Amazon::Ecs.options = {
+ :aWS_access_key_id => configatron.aws_access_key,
+ :aWS_secret_key => configatron.aws_secret_key,
+}
+
+class AmazonInfo
+ class << self
+
+ def book_info(isbn)
+ authors = nil
+ title = nil
+ publisher = nil
+ detailpageurl = nil
+ image = nil
+ source = nil
+ content = nil
+ rating = nil
+ rating_count = nil
+
+ result = Amazon::Ecs.item_lookup(isbn, { :response_group => 'Medium' })
+ if result.has_error?
+ raise ArgumentError, "No Amazon info available"
+ end
+
+ result.items.each do |item|
+ authors = item.get_array('author')
+ title = item.get('title')
+ publisher = item.get('publisher')
+ detailpageurl = item.get('detailpageurl')
+ image = item.get('largeimage/url')
+ reviews = item/'editorialreview'
+ unless reviews.nil?
+ reviews.each do |review|
+ source = Amazon::Element.get_unescaped(review, 'source')
+ content = Amazon::Element.get_unescaped(review, 'content')
+ break
+ end
+ end
+ break
+ end
+
+ result = Amazon::Ecs.item_lookup(isbn, { :response_group => 'Reviews' })
+ result.items.each do |item|
+ rating = item.get('averagerating')
+ rating_count = item.get('totalreviews')
+ break
+ end
+
+ {
+ :info_source => "amazon",
+ :title => title,
+ :authors => authors,
+ :authors_as_string => authors.join(', '),
+ :publisher => publisher,
+ :amazon_url => detailpageurl,
+ :image => image,
+ :review_source => source,
+ :review_content => content,
+ :rating => rating,
+ :rating_count => rating_count,
+ }
+ end
+
+ end
+end
View
19 app/models/bookseer_info.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+
+require 'cgi'
+
+class BookseerInfo
+ class << self
+
+ def link(bookinfo)
+ if bookinfo.nil?
+ "http://bookseer.com"
+ else
+ title = CGI.escape(bookinfo[:title] || "")
+ authors = CGI.escape(bookinfo[:authors_as_string] || "")
+ "http://bookseer.com/?title=#{title}&author=#{authors}"
+ end
+ end
+
+ end
+end
View
24 app/models/flipkart_info.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+class FlipkartInfo
+ class << self
+
+ def book_info(isbn)
+ url = "http://www.flipkart.com/search.php?query=#{isbn}"
+ page = Mechanize.new.get(url)
+
+ product_details = page.search("div.item_details span.product_details_values")
+ title = product_details[0].text.strip
+ publisher = product_details[1].text.strip
+ authors = product_details[6].text.strip
+
+ {
+ :info_source => "flipkart",
+ :title => title,
+ :authors_as_string => authors,
+ :publisher => publisher,
+ }
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.