Sha256: e66759c53a0600bb3200be62579cee801bd83f6ace83470ea20f992150c9e4b1

Contents?: true

Size: 1.76 KB

Versions: 4

Compression:

Stored size: 1.76 KB

Contents

#!/usr/bin/env ruby

require 'date'

require 'terminal-table'

require "rawbotz"
require 'rawbotz/option_parser'
require 'rawbotz/cli/order_result_table'


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

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

include RawgentoModels

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

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

  logger.info("Checking queue")

  queue = RawgentoModels::Order.queued
  logger.info("-> #{queue.count} orders to process")

  if queue.count == 0
    logger.info("Nothing to do, exiting.")
    exit 0
  end

  order = queue.first

  logger.info("#{order.order_items.length} items in Order")

  if order.state != "queued"
    logger.warn("Order in state #{order.state}!")
  end
  order.update(state: :processing)

  logger.info ("#{order.order_items.processible.count} products to order.")

  mech = Rawbotz.new_mech
  mech.login

  order_processor = Rawbotz::OrderProcessor.new(order, logger)
  order_processor.process!

  order.update(state: :ordered)

  logger.info("Finished order")

  logger.info("Checking current cart")
  diffs = order_processor.check_against_cart

  # Option to put to stdout
  diff_table = Rawbotz::CLI::OrderResultTable.tables diffs
  puts diff_table

  if options[:mail]
    logger.debug("Sending mail")
    mail = Rawbotz::mail("rawbotz order finished",
                  "Finished Order nr #{order.id}. Result: [tbd]\n\n#{diff_table}")
    logger.debug("Mail sent: #{mail}")
  else
    logger.debug("not sending mail")
  end
end

main options
exit 0

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rawbotz-0.1.5 exe/rawbotz_process_order_queue
rawbotz-0.1.4 exe/rawbotz_process_order_queue
rawbotz-0.1.3 exe/rawbotz_process_order_queue
rawbotz-0.1.2 exe/rawbotz_process_order_queue