#!/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 would be available, too 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