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
#!/usr/bin/env ruby | |
# -*- coding: utf-8; -*- | |
# README http://www.freedomcat.com/wiki.cgi?page=mm2bs | |
# DATE:2011/08/20 22:04 | |
require 'csv' | |
require 'amazon/aws' | |
require 'amazon/aws/search' | |
include Amazon::AWS | |
csvfile = "your_csv_file" | |
CSV_TITLE = 0 #"タイトル" | |
CSV_LINKURL = 1 #,"リンクURL" | |
CSV_IMG_S_URL = 2 #,"イメージ画像URL(小)" | |
CSV_IMG_M_URL = 3 #,"イメージ画像URL(中)" | |
CSV_CATGORY = 4 #,"カテゴリ" | |
CSV_GENRE = 5 #,"ジャンル" | |
CSV_AUTHOR = 6 #,"著者" | |
CSV_PUBRISH = 7 #,"出版社(発売元)" | |
CSV_PUBDATE = 8 #,"出版日(発売日)" | |
CSV_ISBN = 9 #,"ISBN/JAN" | |
CSV_PRICE = 10 #,"定価" | |
CSV_A_PRICE = 11 #,"アマゾン価格" | |
CSV_ASIN = 12 #,"ASIN(アマゾン商品コード)" | |
CSV_REGDATE = 13 #,"登録日" | |
CSV_TAG = 13 #,"タグ" | |
CSV_COMMENT = 14 #,"コメント" | |
CSV_VALUE = 15 #,"評価" | |
CSV_WISH = 16 #,"ウィッシュ" | |
CSV_HOLD = 17 #,"所有" | |
CSV_FAV = 18 #,"お気に入り" | |
CSV_BUYDATE = 19 #,"購入日" | |
CSV_BUY_PRICE = 20 #,"購入金額" | |
CSV_STATUS = 21 #,"状態" | |
CSV_READ_DATE = 22 #,"読了日" | |
CSV_OPENCLOSE = 23 #,"公開・非公開" | |
reader = CSV.open( csvfile ,'r' ) | |
reader.shift | |
print "タイトル,ジャンル,ページ数,重さ,厚さ(mm),ブックスキャン冊数,キンコーズ冊数\n" | |
reader.each do |row| | |
begin | |
il = ItemLookup.new('ISBN', ItemId: row[CSV_ASIN], SearchIndex: 'Books') | |
request = Search::Request.new | |
response = request.search il | |
item = response.item_lookup_response.items.item | |
pages = item.item_attributes.number_ofpages | |
rescue | |
pages = 0 | |
end | |
begin | |
weight = item.item_attributes.package_dimensions.weight | |
rescue | |
weight = 0 | |
end | |
begin | |
height = item.item_attributes.package_dimensions.height | |
height = (( height.to_i * 25 )/100).ceil | |
rescue | |
height = 0 | |
end | |
# ブックスキャン冊数計算 | |
# (350ページまで1冊。それ以上は200ページごとに1冊追加) | |
if( pages.to_i < 350 )then | |
number_b = 1 | |
else | |
number_b = 2 + ( (pages.to_i - 350)/200 ) | |
end | |
# キンコーズ冊数計算 | |
# 1cmごとに1冊 | |
number_k = 1 + height.to_i.ceil/10 | |
print row[CSV_TITLE] + "," + row[CSV_GENRE] + "," + pages.to_s + ","+ weight.to_s + "," + height.to_s + "," + number_b.to_s + "," + number_k.to_s + "\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment