Sha256: 8a947fa207a3ee76f8973fc95e21aeb0f9db64b7f40c6b5a1a6544296bbd4497

Contents?: true

Size: 1.95 KB

Versions: 3

Compression:

Stored size: 1.95 KB

Contents

#!/usr/bin/env ruby

require 'optparse'
require 'yaml'

options = {:confirm => true, :force => false}
opt_parser = OptionParser.new do |opts|
  opts.banner = "Usage: update_onebody -c path/to/config.yml [options] path/to/people.csv"
  opts.on("-y", "--no-confirm", "Assume 'yes' to any questions") do |v|
    options[:confirm] = false
  end
  opts.on("-l", "--log LOGFILE", "Output to log rather than stdout") do |log|
    $stdout = $stderr = File.open(log, 'a')
  end
  opts.on("-f", "--force", "Force update all records") do |f|
    options[:force] = true
  end
  opts.on("-c", "--config-file PATH", "Path to configuration file") do |c|
    options[:config_file] = c
    config = YAML::load(File.read(c))
    SITE       = config['site']
    USER_EMAIL = config['user_email']
    USER_KEY   = config['user_key']
    if c = config['converter']
      USE_CONVERTER = c['name']
      CONVERTER_CONFIG = c
    end
  end
end
opt_parser.parse!

unless options[:config_file]
  puts opt_parser.help
  puts
  puts 'You must specify a config file containing site and login info.'
  puts "See #{File.expand_path(File.dirname(File.dirname(__FILE__)))}/example.yml"
  puts
  exit
end

if ARGV[0] # path/to/people.csv
  require 'onebody-updateagent'
  puts "Update Agent running at #{Time.now.strftime('%m/%d/%Y %I:%M %p')}"
  agent = PeopleUpdater.new(ARGV[0])
  puts "comparing records..."
  agent.compare(options[:force])
  if agent.has_work?
    if options[:confirm]
      case ask("#{agent.create.length + agent.update.length} record(s) to push. Continue? (Yes, No, Review) ") { |q| q.in = %w(yes no review y n r) }
      when 'review', 'r'
        agent.present
        unless agent.confirm
          puts "Canceled by user\n"
          exit
        end
      when 'no', 'n'
        puts "Canceled by user\n"
        exit
      end
    end
    agent.push
    puts "Completed at #{Time.now.strftime('%m/%d/%Y %I:%M %p')}\n\n"
  else
    puts "Nothing to push\n\n"
  end
else
  puts opt_parser.help
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
seven1m-onebody-updateagent-0.1.2 bin/update_onebody
seven1m-onebody-updateagent-0.1.3 bin/update_onebody
seven1m-onebody-updateagent-0.1.4 bin/update_onebody