#!/usr/bin/env ruby
# rcom_hkft.rb ver.0.1 2002.4.10-2003.1.20
require 'net/http'
require 'cgi'
#require 'simpleuri'
#require 'webagent'
#今のところ早川文庫FT書評リンクのみ
class CacheBib_rcom < CacheBib
attr_accessor :isbn
attr_accessor :flag_review
attr_accessor :url_site
attr_accessor :title, :author, :publisher, :series, :pubdate, :translator
attr_accessor :image, :author_id, :book_id, :comment
attr_accessor :e_title, :e_author, :e_pubdate
attr_accessor :url_ameq, :url_seraeno, :url_buy
attr_accessor :reviews
attr_accessor :insystemKcode, :outputKcode, :messageKcode
def initialize ()
super
@reviews = Array.new()
@flag_review = true
@url_site = 'http://ippo.s5.xrea.com/dk/'
@insystemKcode = 3 #sjis #1-jis,2-euc,3-sjis
@outputKcode = 2 #euc
@messagetKcode = 3 #sjis
end
#===== ===== parts ===== =====
#===== ===== url ===== =====
def url_list
url = @url_site + 'list.html'
return url
end
def url_bibinfo ()
url = @url_site + "isbn#{@isbn.delete('-').upcase}.html"
return url
end
#===== ===== parse ===== =====
def parse_list (str)
@list = []
str.each{ |line|
if line =~ %r|(.+)(.+?)(.+)\((\d+)\)
|i then
@hcode, @url_file, @title, @author, @num_review = $1, $2, $3, $4, $5
if @title =~ /(.+)《(.+)》/s
@title, @series = $1, $2
end
@isbn = isbn_check('4-15-020' + @hcode[2..4].to_s)
record = {}
record["isbn"] = @hcode
record["url_file"] = @url_file
record["h-code"] = @hcode
record["title"] = @title
record["series"] = @series
record["author"] = @author
record["num_review"] = @num_review
@list << record
end
}
end
def parse_bibinfo (str)
#----- set key and data ------
#----- read and sepalate by key(mode_tbl) ------
str.collect{|line| line.chomp.chomp("\r").kconv(@insystemKcode)}
block = str.split(/
/i)
block.shift
return if block.size == 0
#----- parse -----
line = block.shift.delete("\n").split(/
/i)
@publisher = line[0].strip
@hcode = line[1].strip
@title = line[2].strip
@author = line[3].strip
@translater = line[4].strip.chomp("訳")
@pubdate = line[5].strip
@isbn = line[6].strip.gsub(/^ISBN/,'')
@comment = line[7].strip if !line[7].nil?
if @title =~ /(.+)(《(.+)》)?.* \((.+)\)/s
@title, @series, book_id = $1, $2, $4
end
if @author =~ /(.+) \((.+)\)/s
@author, @author_id = $1, $2
if @author_id =~ %r|(.+)|
@url_author, @author_id = $1, $2
end
end
line = block.shift.delete("\n").split(/
/i)
line.each{ |rline|
if rline =~ %r|(.+?) さん (.+?)|
@url_reviewer, @reviewer, @url_review, @title_review = $1, $2, $3, $4
end
review = {}
review["url_reviewer"] = @url_reviewer
review["reviewer"] = @reviewer
review["url_reviewe"] = @url_review
review["title_review"] = @title_review
@reviews << review
}
if block[0] =~ %r|瀬良ヱ野図書館|
# @url_seraeno = $1
# end
line = block.shift.delete("\n").split(/
/i)
@e_title = line[0].strip
@e_author = line[1].strip
@e_pubdate = line[2].strip
line = block.shift
if line =~ %r|AMEQ LAND|
@url_ameq = $1
end
if line =~ %r|瀬良ヱ野図書館|
@url_seraeno = $1
end
if line =~ %r|↓|
@url_buy = $1
end
line = block.shift
if line =~ %r|Last Updated (.+)<|
@lastupdate = $1
else
message = 'WAR; maybe parse error; ' + @isbn
@stderr.puts message.kconv(@messageKcode)
end
end
#===== ===== main ===== =====
def set_info #===== set local-value from @info (from cache) =====
#----- set book-info (from cache) -----
@flag_overprint = true if @info["overprint"]
@isbn = @info["isbn"] unless @info["isbn"].nil?
end
def get_info #===== get book-info(@info) from url =====
message = 'CHK; access; ' + @url_site + ' -> ' + @isbn
@stderr.puts message.kconv(@messageKcode)
#----- get detail-code -----
#----- get book-info -----
agent = WebAgent.new()
agent.uri = url_bibinfo
agent.get()
body = agent.body.kconv(@insystemKcode)
parse_bibinfo(body)
if !@flag_overprint
@info = {}
end
@info["isbn"] = @isbn
@info["title"] = @title
@info["sereis"] = @series
@info["author"] = @author
@info["translator"] = @translator
@info["publisher"] = @publisher
@info["pubdate"] = @pubdate
@info["image"] = @image
@info["author_id"] = @author_id
@info["book_id"] = @book_id
@info["e_title"] = @e_title
@info["e_author"] = @e_author
@info["e_pubdate"] = @e_pubdate
@info["comment"] = @comment
@info["url_ameq"] = @url_ameq
@info["url_seraeno"] = @url_seraeno
@info["url_buy"] = @url_buy
@info["lastupdate"] = @lastupdate
@info["overprint"] = true if @flag_overprint
if @flag_review
@info["reviews"] = @reviews
end
end
end