-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprime-now-me.rb
executable file
·95 lines (76 loc) · 2.72 KB
/
prime-now-me.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
#!/usr/bin/env ruby
require 'selenium-webdriver'
require 'optparse'
require 'net/http'
require 'uri'
def submit_zipcode zip
form = @driver.find_element(id: 'locationSelectForm')
form.find_element(id: 'lsPostalCode').send_keys(zip)
form.submit
sleep 5
@driver.navigate.to @checkout_url
end
def submit_login email, password
form = @driver.find_element(:name, "signIn")
form.find_element(:name, "email").send_keys(email)
form.find_element(:name, "password").send_keys(password)
form.submit
sleep 5
if @driver.page_source.include? "Enter OTP"
puts "Enter OTP: "
otp = STDIN.gets.chomp
form = @driver.find_element(:id, "auth-mfa-form")
form.find_element(id: "auth-mfa-otpcode").send_keys(otp)
form.submit
end
sleep 5
@driver.navigate.to @checkout_url
end
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: prime-now-me.rb [options]"
opts.on('-e', '--email EMAIL', "Amazon account email") do |f|
options[:email] = f
end
opts.on('-p', '--password PASSWORD', "Amazon account password") do |f|
options[:password] = f
end
opts.on('-s', '--sms SMS_PHONE_NO', "phone number of SMS") do |f|
options[:sms] = f
end
opts.on('-z', '--zipcode ZIPCODE', "your delivery zip code") do |f|
options[:zipcode] = f
end
opts.on('-k', '--api-key TEXTBELT_API_KEY', "Textbelt API Key, use key=textbelt to send 1 free text per day, see https://textbelt.com") do |f|
options[:apikey] = f
end
opts.on('-m', '--merchant_id MERCHANT_ID', "Prime Now merchant ID") do |f|
options[:merchant_id] = f
end
end.parse!
raise OptionParser::MissingArgument, "run ./prime-now-me.rb --help for usage" if options[:email].nil? || options[:password].nil? || options[:sms].nil? || options[:apikey].nil? || options[:merchant_id].nil?
@checkout_url = "https://primenow.amazon.com/checkout/enter-checkout?merchantId=#{options[:merchant_id]}&ref=pn_sc_ptc_bwr"
@driver = Selenium::WebDriver.for :safari
@driver.manage.window.maximize
@driver.navigate.to @checkout_url
@driver.manage.timeouts.implicit_wait = 30
submit_zipcode(options[:zipcode]) if @driver.page_source.include? "Enter your ZIP code"
submit_login(options[:email], options[:password]) if @driver.page_source.include? "Sign-In"
while true
@driver.navigate.to @checkout_url
sleep 5
if @driver.page_source.include? "No delivery windows available."
puts "no windows, sleeping for 5 minutes"
sleep 300
else
puts "delivery window found, sending text"
uri = URI.parse("https://textbelt.com/text")
Net::HTTP.post_form(uri, {
phone: options[:sms],
message: 'Prime Now delivery window found!',
key: options[:apikey]
})
# once found, maybe sleep longer here? 12 hours?
sleep 43200
end
end