# 文献を管理することは重要である。 # 文献は大きく分けて論文と書籍に分けられる。 # 今まで論文データ入力支援ツールはあったが、 # 書籍データ入力支援ツールはない(というか、見つけられなかった)。 # このスクリプトを用いれば、管理に必要な書籍データの入力量を大幅に減らせる。 # # = 特徴 # ISBNを入力してあるファイルを元に、bibtex形式で出力します。 # 書籍情報はwww.amazon.co.jpから収集します。 # # = 前提 # 本スクリプト動作に必要な環境は以下の通りです。 # * wwwに接続している。 # * rubyが動作する。 # * not(のとや)さん作の amazon4.rb が動作する。 # # = 使うには # 1. isbn2bibtex.rbを適当な場所に保存してください。(./isbn2bibtex.rbでアクセスできます) # 2. isbn2bibtex.rbと同じディレクトリにnot(のとや)さん作 amazon4.rb を保存してください。 # 3. isbnを入力したisbn.listを同じディレクトリに作成してください。 # 4. 端末上で以下のように入力してださい。 # ruby isbn2bibtex.rb < isbn.list # # = 使い方 # ruby isbn2bibtex.rb < isbn.list > output.bibtex.file # isbn.list :: 10桁の(英)数字からなるリスト。空行はエラーになる。 # 該当するISBNがなくてもエラーになる。 # output.bibtex.file :: 出力先のbibファイル。データ追加なら >> に変更。 # # == 使用例 # # C:\0mine\work>type isbn.list # 4488451012 # # C:\0mine\work>ruby isbn2bibtex.rb < isbn.list # @Book{, # author = {{米澤 穂信(著)}}, # title = {{ 春期限定いちごタルト事件 }}, # publsher = {{ 東京創元社 }}, # year = { 2004-12-18 }, # annote = { }, # ISBN = { 4488451012 } # } # isbn2bibtex.rb:49: private method `chop' called for nil:NilClass (NoMethodError) # # 最後のchopはオマケみたいなもんです。 # 元のisbn.listで空白行があると怒られます。 # 直し方分かる人教えてください。 # # == スクリプトからの呼出し例 # スクリプト最後尾。 # aws = Amazon::WebService::new # item = aws.itemlookup('4488451012') # puts item.to_text_book # # 実行結果。 # C:\0mine\work>ruby isbn2bibtex.rb # @Book{, # author = {{米澤 穂信(著)}}, # title = {{ 春期限定いちごタルト事件 }}, # publsher = {{ 東京創元社 }}, # year = { 2004-12-18 }, # annote = { }, # ISBN = { 4488451012 } # } # # = TODO # * エラー処理 # * Amazon.co.jp に繋がらない場合 # * Amazon.co.jp で捜したけどISBNが見つからない場合 # * 一致するISBNは見つかったけど、途中の文字列が無い場合 # * Amazon.co.jp以外への対応 # # これはnot(のとや)さん作 amazon4.rb が機能することを前提にしたスクリプトです。 require 'amazon4.rb' # # module Amazon # amazon4.rbで定義されている Item class を拡張 # class Item def to_bibtex return '' if text('//ProductGroup').empty? case text('//ProductGroup')[0] when 'Book' to_bibtex_book # when 'CE' # to_bibtex_ce # when 'Kitchen' # to_bibtex_kitchen # when 'Music' # to_bibtex_music # when 'DVD', 'Video' # to_bibtex_dvd # when 'Software' # to_bibtex_software # when 'Video Games' # to_bibtex_videogames # when 'Toy' # to_bibtex_toy else to_bibtex_base end end private def to_bibtex_base() "bibtex base" end ## # 本のデータをbibtex 形式にして出力。 # 他の形式のデータの処理は不明。 # # Title :: #{text('//Title')} # Publisher :: #{text('//Publisher')} # Author :: #{author} # Binding :: #{text('//Binding')} # Price :: #{text('//OfferSummary/LowestNewPrice/FormattedPrice')} # PublicationDate :: #{text('//PublicationDate')} # ISBN :: #{hyphened_isbn(text('//ASIN')[0])} # raw-ISBN :: #{text('//ASIN')[0]} # def to_bibtex_book author = page = '' t = text('//Creator', 'Role') if t.size.nonzero? then author = t.join(', ') end t = text('//NumberOfPages') if t.size.nonzero? then page ="#{t}ページ / " end "\@Book{, author = \{\{#{author}\}\}, title = \{\{ #{text('//Title')} \}\}, publsher = \{\{ #{text('//Publisher')} \}\}, year = \{ #{text('//PublicationDate')} \}, annote = \{ \}, ISBN = \{ #{text('//ASIN')[0]} \} }" end end end ## # フィルタ用メインループ aws = Amazon::WebService::new while isbn_num = gets.chop exit if isbn_num=="" item = aws.itemlookup(isbn_num) puts item.to_bibtex end exit