Sha256: a14f1ba11a704af339bd0ea9b941aed7f205bc3c71ecafdddabb2708cdf566a9

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

#!/usr/bin/env ruby

require "rawbotz"
require "rawbotz/option_parser"

optparse = Rawbotz::OptionParser.new do |opts, options|
  opts.banner = "Usage: #{$PROGRAM_NAME} [OPTIONS]"
  opts.separator ""

  opts.on("-m", "--[no-]mail",
          "send mail with result") do |v|
    options[:mail] = v
  end
end
optparse.parse!
options = optparse.options

logger = Logger.new(STDOUT)
logger.level = optparse.options[:verbose] ? Logger::DEBUG : Logger::INFO

logger.debug "#{$PROGRAM_NAME} #{Rawbotz::VERSION}"

logger.info("Fetching and updating local products from MySQL database")

begin
  products = RawgentoDB::Query.products
rescue
  logger.error "Could not connect to MySQL database or other error"
  #logger.error "$!.inspect" $@ -> backtrace
  exit 1
end

product_count = RawgentoModels::LocalProduct.unscoped.count

updater = Rawbotz::ProductUpdater.new logger
updater.sync

logger.info("Finished updating local products.")

logger.info("Found #{RawgentoModels::LocalProduct.unscoped.count - product_count}  new products")

if options[:mail]
  logger.debug("Sending mail")
  Rawbotz::mail("rawbotz local product update",
                "Found #{RawgentoModels::LocalProduct.unscoped.count - product_count} new local products")
end

exit 0

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rawbotz-0.1.4 exe/rawbotz_update_local_products
rawbotz-0.1.3 exe/rawbotz_update_local_products
rawbotz-0.1.2 exe/rawbotz_update_local_products