#!/usr/bin/env ruby # asahiya.rb # ver.0.2 2002.04.05-2003.01.20 # ver.0.3 2004.01.06-2004.01.07 VƒLƒƒƒbƒVƒ…‚ɑΉž #reference: # isbn2book.rb http://www3.ocn.ne.jp/~han/ndiary/index.html ‚É—ÞŽ— if __FILE__ == $0 require 'cookie' require 'webagent' require 'cache' require 'cachebib' end class CacheBib_asahiya < CacheBib attr_accessor :subtitle def initialize () super @shop_id = 'ash' @url_site = 'http://www.netdirect.co.jp/' end #===== ===== parts ===== ===== def word_delivery () return word_stock end def word_stock () stock = '' flag = false if !@title.nil? # title-check -> no-info / get-info check flag = true if @stock.nil? stock = "‚È‚¢" else if @stock =~ // stock = "݌ɑ½" elsif @stock =~ /›/ stock = "݌ɗL" elsif @stock =~ /¢/ stock = "݌ɭ" elsif @stock =~ /¦/ stock = "ŽæŠñ" elsif @stock =~ /~/ stock = "•s‰Â" else stock = "H" end end else message("WAR; maybe data-error, no-title.") end return stock, flag end #===== ===== url ===== ===== def url_isbnsearch ( isbn = @isbn ) url_bibinfo(isbn) end def url_bibinfo ( id = @id ) id = @isbn if id.nil? id = id.delete('-').upcase url = @url_site + "search/ISSSchDetail.asp?ISBN=#{id}" return url end #===== ===== parse ===== ===== def parse_bibinfo ( str ) #----- set key and data ------ mode_tbl = { # # :title => '', # + image # :image => '', :subtitle => '•›‘èF', :label => 'ƒVƒŠ[ƒY–¼F', :author => '’˜ŽÒF', :translator => '–óŽÒF', :publisher => 'o”ÅŽÐF', :price => 'ŕʉ¿ŠiF', :isbn => 'ISBNF', :genre => 'ISBNC•ª—ÞF', :pubdate => '”­sF', :stock => 'ÝŒÉó‹µF', # # :desc => 'y Љ z', :index => 'y –ÚŽŸ z', :none => '' } mode = :none data = Hash.new() #----- read and sepalate by key(mode_tbl) ------ str.each{|line| l = line.chomp.chomp("\r").kconv(@insystemKcode) mode_tbl.each{ |key,keydata| mode = key if /#{keydata}/s =~ l } if mode != :none if data[mode] data[mode] << l else data[mode] = l end end } #----- parse ----- @title = data[:title].to_s.gsub(/<[^>]+>/,'').strip if data[:title] =~ /]*?)\"[^>]*?ALT=\"¤•iƒCƒ[ƒW\">/s @image = @url_site.chomp('/') + $1 end subtitle = data[:subtitle].to_s.sub(/#{mode_tbl[:subtitle]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @subtitle = subtitle if subtitle != '' label = data[:label].to_s.sub(/#{mode_tbl[:label]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @label = label if label != '' author = data[:author].to_s.sub(/#{mode_tbl[:author]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @author = author if author != '' translator = data[:translator].to_s.sub(/#{mode_tbl[:translator]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @translator = translator if translator != '' publisher = data[:publisher].to_s.sub(/#{mode_tbl[:publisher]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @publisher = publisher if publisher != '' price = data[:price].to_s.sub(/#{mode_tbl[:price]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @price = price if price != '' isbn = data[:isbn].to_s.sub(/#{mode_tbl[:isbn]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @isbn = isbn if isbn != '' genre = data[:genre].to_s.sub(/#{mode_tbl[:genre]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @genre = genre if genre != '' pubdate = data[:pubdate].to_s.sub(/#{mode_tbl[:pubdate]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @pubdate = pubdate if pubdate != '' stock = data[:stock].to_s.sub(/#{mode_tbl[:stock]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip stock.gsub!(/\(.*?\).*/,'').strip! @stock = stock if stock != '' if !data[:desc].nil? if data[:desc] =~ /#{mode_tbl[:index]}/ data[:desc], data[:index] = $`, $& + $' end desc = data[:desc].sub(/#{mode_tbl[:desc]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @desc = desc if desc != '' end if !data[:index].nil? index = data[:index].sub(/#{mode_tbl[:index]}/s,'').gsub(/<[^>]+>/,'').gsub(/ ?/,'').strip @index = index if index != '' end end #===== ===== get/set info ===== ===== def preset_info #===== set local-value from @info (from cache) ===== super @id = @isbn.delete('-').upcase #@info["id"] @stock = @info["stock"] end def set_info #===== set book-info(@info) from local-value ===== super #----- set info add ----- #ˆ®‰®“ÆŽ©‚Ìî•ñ—Þ @info["subtitle"] = @subtitle #•›‘è end end if __FILE__ == $0 p CacheBib_asahiya.new.get_data('4-15-010739-4') # p CacheBib_asahiya.new.get_data('4140808403') # p CacheBib_asahiya.new.get_data('4873762456') end