5 require "rexml/document"
\r
6 require "rexml/xpath"
\r
11 puts "this will take a while..."
\r
12 contents = open(ARGV[0], 'r') { |f| f.read }
\r
13 puts "finished reading in file..."
\r
14 contents.gsub!("\n", '')
\r
16 puts "splitting the file up!"
\r
17 records = contents.split('<?xml version="1.0" encoding="UTF-8"?>')
\r
21 really_good_matches = 0
\r
26 records.each do |record|
\r
27 next if record == ""
\r
28 puts "---------------------------"
\r
29 puts "rexml is reading in the contents of a record..."
\r
30 rec = REXML::Document.new record
\r
31 puts rec.elements["explain/recordInfo"]
\r
33 #puts rec.elements["databaseInfo/title"].text
\r
34 if rec.elements["explain/databaseInfo/title"]
\r
35 puts "Looking in #{rec.elements["explain/databaseInfo/title"].text} ..."
\r
39 if rec.elements["explain/recordInfo/recordSyntax[@name='usmarc']"] || rec.elements["explain/recordInfo/recordSyntax[@name='USmarc']"]
\r
41 #get record syntaxes supported
\r
43 rec.elements.each("explain/recordInfo/recordSyntax") do |syn|
\r
44 syntaxes << syn.attributes["name"]
\r
48 if rec.elements["explain/serverInfo[@protocol='Z39.50']"]
\r
49 puts "we've got a match!"
\r
52 #how reliable is the target?
\r
54 rec.elements.each("explain/irspy:status/irspy:probe") do | elem |
\r
55 a << elem.attributes["ok"]
\r
64 unless a.length == 0
\r
65 ok = 100.0 * (total.to_f / a.length.to_f)
\r
67 puts "not a reliable site!"
\r
77 line = "- [ " + rec.elements["explain/serverInfo/host"].text + ", "
\r
78 line << rec.elements["explain/serverInfo/port"].text + ", "
\r
79 line << rec.elements["explain/serverInfo/database"].text
\r
81 num = 100 - ok.floor + 10 + rand(90)
\r
82 line << ", #{num}] #"
\r
85 line << ", #{ok.floor + 100}] #"
\r
88 line << rec.elements["explain/databaseInfo/title"].text if rec.elements["explain/databaseInfo/title"] && rec.elements["explain/databaseInfo/title"].text
\r
89 line << " " + ok.floor.to_s + '%' if ok
\r
90 line << " | " + syntaxes.join(", ")
\r
93 all_lines << line << "\n"
\r
98 puts "matches: #{match}"
\r
101 File.open("irspy-#{Time.now.strftime("%Y%m%d%H%M%S")}\.yaml", "w") do |f|
\r
105 puts oks.join(", ")
\r
106 puts "------------------------"
\r
108 puts nums.join(" + ")
\r
110 # puts "really reliable 98%+: #{really_good_matches}"
\r
111 #puts "reliable 95%+: #{good_matches}"
\r
112 #puts "still good 90%+ #{ok_matches}"
\r