28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/auto_bidder.rb', line 28
def parse_command_line
options = {}
optparse = OptionParser.new do|opts|
opts.banner = "Usage: auto-bidder [options] URL"
options[:verbose] = false
opts.on('-v', '--verbose', 'Be more verbose') do
options[:verbose] = true
end
opts.on("-x", "--max-price PRICE", Float, 'Maximum price you are willing to pay for the auction item') do |max_price|
options[:max_price] = max_price
end
opts.on("-n", "--min-price [PRICE]", Float, 'Minimum price the auction item must reach before bidding starts') do |min_price|
options[:min_price] = min_price || 0.0
end
opts.on("-c", "--bid-cost COST", Float, 'How much each bid actually costs you') do |bid_cost|
options[:bid_cost] = bid_cost
end
opts.on("-u", "--username USER", 'Username of your account for the auction site') do |username|
options[:username] = username
end
opts.on("-s", "--bid-seconds [SECONDS]", Integer, 'How many seconds remaining on the clock before a bid is placed') do |bid_secs|
options[:bid_secs] = bid_secs || 1
end
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
optparse.parse! ARGV
ensure_option_is_present options, :max_price, optparse
ensure_option_is_present options, :bid_cost, optparse
ensure_option_is_present options, :username, optparse
url = ARGV[0]
unless url
puts "URL must be given"
puts optparse
exit 1
end
ARGV.clear
if options[:username]
print "Auction site password:"
begin
system "stty -echo"
options[:password] = gets.chomp
puts ensure
system "stty echo"
end
end
$log = Logger.new(STDOUT)
$log.level = options[:verbose] ? Logger::DEBUG : Logger::INFO
$log.debug "Verbose logging turned on" if $log.debug?
[url, options]
end
|