9 require 'highline/import'
10 require 'term/ansicolor'
11 #include Term::ANSIColor
24 termsize
= HighLine
::SystemExtensions.terminal_size
25 $term_width = termsize
[0]
26 $term_height = termsize
[1]
27 $clear_code = %x{clear}
28 HighLine.track_eof = false
30 ##Setting up testing parameter
32 $testing = nil unless $testing == 'v' or $testing == 't'
33 file_mode = true if ARGV[0] == 'file'
34 puts "We're testing " if $testing
35 STDIN.gets if $testing
37 #reading in config from yaml file
38 yamlfile = YAML.load_file( "#{File.expand_path("~")}/.zcc/zcc.yaml" )
39 zservers = yamlfile['zservers']
42 #puts zservers[0][0].class
44 #puts zservers[0][0] =~ /Include/
46 if zservers[0][0] =~ /Include/
48 filename = zservers[0][0][8, 99]
49 contents = YAML.load_file("#{File.expand_path("~")}/.zcc/#{filename}")
52 contents.each{|c| zservers.push(c)}
56 #puts zservers.inspect
61 labels = yamlfile['labels']
62 scripting = yamlfile['scripting']
63 $procs = yamlfile['procs']
65 TO_SHOW = yamlfile['to_show']
66 SHOW_PER_PAGE = yamlfile['show_per_page']
67 HOW_TO_SAVE = yamlfile['save_filename']
68 TIMESTAMP = Time.now.strftime("%Y%m%d%H%M%S")
69 SCRIPTING = yamlfile['scripting_on']
70 EDITING = yamlfile['subfield_editing']
71 CSV = yamlfile['csv_on']
72 LINTER = yamlfile['linter_on']
73 FORMAT_TO_SAVE = yamlfile['save_record_syntax']
76 #printed once when starting the program.
77 say("Zcc, Copyright (C) 2007 Jason Ronallo\nZcc comes with ABSOLUTELY NO WARRANTY.\nZcc is released under the terms of the GPL v.2 or later.\nSee LICENSE for full information.\n".bold)
78 say("Simply enter a title, LCCN or ISBN and hit enter.\nTitle: enter the title exactly as it is on the source\n for better relevancy ranking by title.\nLCCN: Include the dash, like 81-21962\nEnter ISBNs without dashes.\nNot all servers accept it, but you can also do a narrowing search\nby including an author's name after the title like so:\nFinnegans Wake :au Joyce")
79 say("For more help see: http://zcc.rubyforge.org/zcc.html")
82 zservers.each do |server|
83 zserver_objects << Zserver.new(server[0], server[1], server[2], server[3])
86 server_h = Hash.new {|hash, key| hash[key] = [] }
87 zserver_objects.each {|z| server_h[z.group] << z}
90 server_h.each_key{|k| groups << k}
95 search_term = ask("\nEnter search. [ISBN, title, LCCN (with dash), or :q to quit]\nsearch> ".boldz, String){ |q| q.readline = true }
96 exit if search_term == ':q'
99 groups.each do |group|
102 servers = server_h[group] #zserver_objects.find_all{|server| server.group == group }
103 #puts "searching the following servers: #{servers.join("...\n")}"
105 query = Query.new(search_term, servers)
106 results = query.search(TO_SHOW)
107 results.index_pos = SHOW_PER_PAGE - 1
108 #print "results.class" ; puts results.class
109 if results.records.empty?
110 puts "There are no results from group #{group} servers!\n\n\n"
111 another_group = ask("Do you want to continue searcing the next group of servers? [y], anything ".boldz)
112 if another_group == 'y' || another_group == ''
120 results.rank_by_relevance!
121 return_value = zcc_select_good_marc(results, 'multi')
123 break if return_value == 'done'
127 taken.remove_unselected!
131 say("\aThis is your combined result set.\nWe will winnow until you choose ".white.bold.on_black + "'done'".red.bold + "\nor you unselect all records.".white.bold.on_black)
134 return_value = zcc_select_good_marc(taken, 'multi')
135 #taken.remove_unselected!
136 #continue = false if taken.length == 0
137 continue = false if taken.selected_length == 0
138 continue = false if return_value == 'done'
140 taken.remove_unselected!
141 unless taken.length == 0
142 puts "Here are the records you've selected for processing:"
143 taken.each do |record|
149 taken.records.each do |final_taken|
151 #SCRIPTING and EDITING
155 say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
156 say("SCRIPTING...".bold.white.on_black)
157 final_taken.local_script(scripting)
163 say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
164 edit = ask("Would you like to " + "edit".headline + " this record [yes or ANYTHING]? ")
165 if edit == ('y' or 'yes')
167 say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
173 say("#{'-'*20}FINAL RECORD#{'-'*20}".headline)
174 say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
175 say("#{'-'*20}FINAL RECORD#{'-'*20}".headline)
176 to_save_or_not_to_save = ask("Would you like to keep this FINAL RECORD? (ANYTHING or n)")
178 if to_save_or_not_to_save == 'n'
179 next #if continue? == 'again'
185 say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}")
186 say("Label making time!".headline)
187 csv = final_taken.marc_to_csv(labels)
188 print "Final csv:\n#{csv}\n"
192 clear_code_do = false
195 #saves in the directory in which zcc was run
196 if HOW_TO_SAVE == 'search_term'
197 filename = search_term.gsub(' ','_')
198 elsif HOW_TO_SAVE == 'timestamp'
202 FORMAT_TO_SAVE.each do |format|
205 aFile = File.new("#{filename}\.mrc","a+")
206 aFile.write(final_taken.marc.to_marc)
207 puts "#{final_taken.marc['245']['a']} saved in #{filename}\.mrc"
210 elsif format == 'xml'
211 #puts final_taken.marc.to_xml
212 aFile = File.new("#{filename}\.xml","a+")
213 aFile.write(final_taken.marc.to_xml)
214 puts "#{final_taken.marc['245']['a']} saved in #{filename}\.xml"
216 elsif format == 'zebra'
217 #puts final_taken.to_xml
218 File.open("#{File.expand_path("~")}/.zcc/zebra/records/#{Time.now.strftime("%Y%m%d%H%M%S")}\.mrc", "w") do |f|
219 f.write final_taken.marc.to_marc
221 Dir.chdir("#{File.expand_path("~")}/.zcc/zebra") do
222 record_update = `zebraidx update records`
225 #saving to koha2 is untested. Please let me know if it doesn't work--or even if it does.
226 elsif format == 'koha2'
228 out = Tempfile.new("koha2-")
229 out << final_taken.marc.to_marc
231 koha_save = `perl /usr/local/koha/intranet/scripts/misc/migration_tools/bulkmarcimport.pl -v 6 -file #{out.path}`
239 csvFile = File.new("csv-#{filename}\.txt","a+")
241 puts "csv for #{final_taken.marc['245']['a']} saved in csv-#{filename}\.txt"