#!/usr/bin/env ruby class CacheBib_rakuten #+++++++++++ ippo ************ def message ( str = '???: message-error.', kcode = @messageKcode ) @stderr.puts str.kconv(kcode) end #===== ===== url ===== ===== def url_ippo_bibinfo () url = 'http://ippo.itbdns.com/cgi/cache/bookcache.cgi?' url << "shop=rak;" url << "isbn=#{@isbn}" return url end #===== ===== parse ===== ===== def parse_ippo_bibinfo ( str ) read_cache_ippo(str) @flag_download = true end def read_cache_ippo ( str = nil ) # ( @file, @flag, @info, @hold_keys ) if @flag #----- already read cache ----- message("WAR; cache-reread-request. already readed. FILE; " + @file.to_s) return end begin #----- \n\n-sepalate ----- texts = [] text = [] str = open(@file).read if str.nil? str.each{ |line| string = (line.chomp.chomp("\r")).kconv(@insystemKcode) if string != "" text << string else texts << text text = [] end } texts << text #----- book-info ----- texts.shift.each{ |line| record = line.split(/\t/) key = record.shift data = record.join("\t") @info[key] = data } #----- review-info ----- if texts.size > 0 reviews = [] texts.each{ |text| reviewinfo = {} text.each { |line| record = line.split(/\t/) key = record.shift data = record.join("\t") reviewinfo[key] = data } reviews << reviewinfo } @info["reviews"] = reviews end #----- hold-keys-info ----- unless @info["hold_keys"].nil? @hold_keys = @info["hold_keys"].split end @flag = true #cache読込済フラグを起す rescue message("CHK; cannot read cahce. FILE; " + @file.to_s) @flag = nil end end #===== ===== get/set info ===== ===== #ここをコメントアウトすると、贋書店巡りをしなくなる。 #=begin alias :orig_get_info :get_info def get_info #===== get book-info(@info) from url ===== begin message('CHK; access; ' + 'http://ippo.itbdns.com/cgi/cache/ rak' + ' -> ' + @isbn) #----- get book-info ----- agent = WebAgent.new() agent.uri = url_ippo_bibinfo agent.get() body = agent.body.kconv(@insystemKcode) parse_ippo_bibinfo(body) set_info rescue orig_get_info end end #=end end