#!/usr/bin/ruby -w ## Jason Ronallo # April, 2007 require 'rubygems' require 'zoom' require 'marc' require 'stringio' require 'yaml' $KCODE = 'u' require 'jcode' require 'unicode' #--my modules require 'zcc/marcadditions' require 'zcc/pickers' require 'zcc/subfieldeditor' require 'zcc/zoomer' #require 'wcid' require 'highline/import' #require 'curses' termsize = HighLine::SystemExtensions.terminal_size $term_width = termsize[0] $term_height = termsize[1] $clear_code = %x{clear} ft = HighLine::ColorScheme.new do |cs| cs[:headline] = [ :bold, :white, :on_black ] cs[:horizontal_line] = [ :bold, :white, :on_blue] cs[:even_row] = [ :green ] cs[:odd_row] = [ :magenta ] cs[:marc_tag] = [:bold] cs[:bolder] = [:bold] cs[:field_hilite] = [:bold, :blue] cs[:index] = [:bold, :red] end HighLine.color_scheme = ft ##Setting up testing parameter $testing = ARGV[0] $testing = nil unless $testing == 'v' or $testing == 't' puts "We're testing " if $testing STDIN.gets if $testing #reading in config from yaml file yamlfile = YAML.load_file( "#{File.expand_path("~")}/.zcc/zcc.yaml" ) zservers = yamlfile['zservers'] labels = yamlfile['labels'] scripting = yamlfile['scripting'] $procs = yamlfile['procs'] TO_SHOW = yamlfile['to_show'] HOW_TO_SAVE = yamlfile['save_filename'] TIMESTAMP = Time.now.strftime("%Y%m%d%H%M%S") SCRIPTING = yamlfile['scripting_on'] EDITING = yamlfile['subfield_editing'] CSV = yamlfile['csv_on'] LINTER = yamlfile['linter_on'] FORMAT_TO_SAVE = yamlfile['save_record_syntax'] #ZEBRA_ON = yamlfile['zebra'] #ZEBRA_CONF = yamlfile['zebraconf'] print $clear_code #printed once when starting the program. 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") say("Introductory help. For now see: http://zcc.rubyforge.org/zcc.html") #++# All the main logic of the program is just one simple big loop. # Copy cataloging forever.... clear_code_do = false loop { taken = [] print $clear_code if clear_code_do clear_code_do = true search_term = ask("\n<%= color('Enter search. [ISBN, title, LCCN (with dash), or :q to quit]', :bolder) %>\nsearch> ", String){ |q| q.readline = true } exit if search_term == ':q' zservers.each do |zserver| records = ZCC.zoomer(search_term, zserver[0], zserver[1], zserver[2]) puts "\n" if records.nil?: print "nil records returned"; next; end recs_array = records.to_a taker = [] taker = recs_array.zcc_select_good_marc('multi') another_zserver = taker.pop if taker[-1] == 'done' next if taker == nil taker.each do |taker| puts "\ntaker: #{taker['245']}\n\n" taken << taker end break if another_zserver == 'done' end taken.flatten! taken.compact! puts "taken.length #{taken.length}" if taken.length > 1 say("\a<%= color('#{'!' * 10}We only need one record per book, so make your choice now!#{'!' * 10}', :headline) %>") sleep 2 taken = taken.zcc_select_good_marc('one') if taken == 'none' next print $clear_code end puts "after selecting final record taken.length = #{taken.length}" puts taken[0]['245'] , "\n\n" elsif taken.length == 0 print $clear_code print "You didn't get any records!\n" clear_code_do = false next #if continue? == 'again' end final_taken = taken[0] #puts final_taken #SCRIPTING and EDITING if SCRIPTING print $clear_code print "\a" say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}") say("<%= color('SCRIPTING...', :headline) %>") final_taken.local_script(scripting) end if EDITING print $clear_code print "\a" say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}") say("Would you like to <%= color('edit', :headline) %> this record [yes or ANYTHING]? ") edit = STDIN.gets.chomp if edit == ('y' or 'yes') print $clear_code say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}") final_taken.edit end end print $clear_code say("<%= color('#{'-'*20}FINAL RECORD#{'-'*20}', :headline) %>") say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}") say("<%= color('#{'-'*20}FINAL RECORD#{'-'*20}\a', :headline) %>") print "Would you like to keep this FINAL RECORD? (ANYTHING or n)" to_save_or_not_to_save = STDIN.gets.chomp if to_save_or_not_to_save == 'n' next #if continue? == 'again' end if CSV print $clear_code print "\a" say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}") say("<%= color('Label making time!', :headline) %>") csv = final_taken.marc_to_csv(labels) print "Final csv:\n#{csv}\n" end print $clear_code clear_code_do = false #saves in the directory in which zcc was run if HOW_TO_SAVE == 'search_term' filename = search_term.gsub(' ','_') elsif HOW_TO_SAVE == 'timestamp' filename = TIMESTAMP end if FORMAT_TO_SAVE == 'marc' aFile = File.new("#{filename}\.mrc","a+") aFile.write(final_taken.to_marc) puts "#{final_taken['245']['a']} saved in #{filename}\.mrc" aFile.close elsif FORMAT_TO_SAVE == 'marcxml' puts final_taken.to_xml aFile = File.new("#{filename}\.xml","a+") aFile.write(final_taken.to_xml) puts "#{final_taken['245']['a']} saved in #{filename}\.xml" aFile.close elsif FORMAT_TO_SAVE == 'zebra' #puts final_taken.to_xml File.open("#{File.expand_path("~")}/.zcc/zebra/records/#{Time.now.strftime("%Y%m%d%H%M%S")}\.xml", "w") do |f| f.write final_taken.to_xml end end if CSV csvFile = File.new("csv-#{filename}\.txt","a+") csvFile.write(csv) puts "csv for #{taken[0]['245']['a']} saved in csv-#{filename}\.txt" csvFile.close end }