Last active
August 29, 2015 14:00
-
-
Save soramugi/11105700 to your computer and use it in GitHub Desktop.
This file contains 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
require 'open-uri' | |
require 'amazon/ecs' | |
jans = [] | |
url = 'http://www.bookoffonline.co.jp/display/L001,sk=10,bg=120902,row=50,pr=u-108,st=u,' | |
1.upto(30).map {|i| url + "p=#{i},"}.each do |url| | |
doc = Nokogiri::HTML(open(url), nil, 'CP932') | |
doc.css('.itemttl').each do |link| | |
path = link.xpath('a')[0].attributes['href'].value | |
book_url = "http://www.bookoffonline.co.jp#{path}" | |
$stdout = StringIO.new | |
doc = Nokogiri::HTML(open(book_url), nil, 'CP932') | |
jan = doc.css('.infotxt/table').map do |infotxt| | |
infotxt.xpath('tr')[2].xpath('td')[0].text rescue nil | |
end.compact.first || nil | |
$stdout = STDOUT | |
jans << jan if jan | |
sleep 10 | |
end | |
end | |
Amazon::Ecs.options = { | |
AWS_access_key_id: ENV['AWS_ACCESS_KEY_ID'], | |
AWS_secret_key: ENV['AWS_SECRET_KEY'], | |
associate_tag: ENV['ASSOCIATE_TAG'], | |
country: 'jp', | |
} | |
jans.each_slice(10).each do |ids| | |
p ids | |
res = Amazon::Ecs.item_lookup( | |
ids.join(','), | |
id_type: 'EAN', | |
search_index: 'Books', | |
response_group: 'OfferSummary,ItemAttributes', | |
) | |
res.items.each do |item| | |
item_attributes = item.get_element('ItemAttributes') | |
title = item_attributes.get_unescaped('Title') | |
jan = item_attributes.get_unescaped('EAN') | |
offer_summary = item.get_element('OfferSummary') | |
new_price = offer_summary.get_unescaped('LowestNewPrice/Amount') rescue nil | |
used_price = offer_summary.get_unescaped('LowestUsedPrice/Amount') rescue nil | |
p "jan: #{jan} new_price: #{new_price} used_price: #{used_price} title: #{title}" if used_price.to_i > 300 | |
end | |
sleep 10 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment