forked from jarodschneider/evga-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evga_bot.py
163 lines (133 loc) · 7.36 KB
/
evga_bot.py
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#Copyright (c) 2020 Austin Simpson
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time
names_to_model = {
"RTX 3080 FTW3 ULTRA": "10G-P5-3897-KR",
"RTX 3080 XC3 GAMING": "10G-P5-3883-KR",
"RTX 3080 XC3 BLACK GAMING": "10G-P5-3881-KR",
"RTX 3080 XC3 ULTRA GAMING": "10G-P5-3885-KR",
}
login_url = "https://secure.evga.com/US/login.asp"
url_template = "https://www.evga.com/products/product.aspx?pn={}"
cart_url = "https://www.evga.com/products/ShoppingCart.aspx"
out_of_stock_message_id = "LFrame_pnlOutOfStock"
add_to_cart_button_id = "LFrame_btnAddToCart"
checkout_button_id = "LFrame_CheckoutButton"
agree_tos_checkbox_id = "cbAgree"
checkout_continue_button_id = "ctl00_LFrame_btncontinue"
modal_checkout_continue_button_id = "ctl00_LFrame_ImageButton2"
credit_card_radio_id = "rdoCreditCard"
cardholder_name_input_id = "ctl00_LFrame_txtNameOnCard"
credit_card_input_id = "ctl00_LFrame_txtCardNumber"
expiration_month_id = "ctl00_LFrame_ddlMonth"
expiration_year_id = "ctl00_LFrame_ddlYear"
cvv_input_id = "ctl00_LFrame_txtCvv"
agree_tos_checkbox_part_two_id = "ctl00_LFrame_cbAgree"
def get_user_info():
print ("Which model do you wish to buy?\n\n(If you do not see the card you want, you may also enter a product number. Bear in mind, I am not doing any validation. Make sure you choose a valid option.)")
#Enumerate all of the possible values (friendly name) to user.
for name in names_to_model.keys():
print ("\t{}".format(name))
#Accept input from the user
part_name_user_input = input()
model_number = ""
#If we find the name in our keys, then we use the mapped part number
if (part_name_user_input in names_to_model.keys()):
model_number = names_to_model[part_name_user_input]
#Otherwise, we assume that the user entered a part number.
else:
model_number = part_name_user_input
print ("Model number selected: {}\nYou will now need to enter payment information. This is information is stored in memory only (IE not written to a file or sent to the cloud).".format(model_number))
print("What is the cardholder name: ")
cardholder_name = input()
print("Please enter your card number (NOT validated): ")
card_number = input()
print("Please enter your security code: ")
security_code = input()
print("Please enter your expiration month (MM): ")
expiration_month = input()
print("Please enter your expiration year (YYYY): ")
expiration_year = input()
return {
"model_number": model_number,
"cardholder_name": cardholder_name,
"card_number": card_number,
"security_code": security_code,
"expiration_month": expiration_month,
"expiration_year": expiration_year,
}
def open_browser():
firefox_instance = webdriver.Firefox()
firefox_instance.get(login_url)
return firefox_instance
def add_card_to_cart(model_number, driver_instance: webdriver.Firefox):
#Default is we're out of stock. We want to refresh the page on a minute interval until we see our card become available.
out_of_stock = True
while out_of_stock:
driver_instance.get(url_template.format(model_number))
try:
#We check to see if the add to cart button is present on the page. If it isnt, the except line will get called and we conclude that the item is not in stock
driver_instance.find_element_by_id(add_to_cart_button_id)
out_of_stock = False
except:
print ("Item is still out of stock. Refreshing in one minute.")
#Don't change this value, as we don't want to DDOS evga. Also, this could indeed backfire if you set it too low and the page can't load before the next call to refresh happens.
time.sleep(60)
#Once it's finally in stock, add the card to the cart.
driver_instance.find_element_by_id(add_to_cart_button_id).click()
print ("Item added to cart.")
def checkout(web_driver: webdriver.Firefox, user_selections):
web_driver.get(cart_url)
#Starts the checkout process
web_driver.find_element_by_id(checkout_button_id).click()
#Verifies and ships using default shipping info
web_driver.execute_script("CheckShippingAddress()")
time.sleep(2)
web_driver.execute_script("ChoiceAddress()")
time.sleep(2)
web_driver.find_element_by_id(agree_tos_checkbox_id).click()
web_driver.find_element_by_id(checkout_continue_button_id).click()
time.sleep(2)
#I only support credit card purchases at this time.
web_driver.find_element_by_id(credit_card_radio_id).click()
web_driver.find_element_by_id(checkout_continue_button_id).click()
#Populate credit card info
web_driver.find_element_by_id(cardholder_name_input_id).send_keys(user_selections["cardholder_name"])
web_driver.find_element_by_id(credit_card_input_id).send_keys(user_selections["card_number"])
web_driver.find_element_by_id(cvv_input_id).send_keys(user_selections["security_code"])
Select(web_driver.find_element_by_id(expiration_month_id)).select_by_value(user_selections["expiration_month"])
Select(web_driver.find_element_by_id(expiration_year_id)).select_by_value(user_selections["expiration_year"])
#Submit and wait for card info to get validated
web_driver.find_element_by_id(modal_checkout_continue_button_id).click()
time.sleep(10)
#Press final agree box
web_driver.find_element_by_id(agree_tos_checkbox_part_two_id).click()
time.sleep(2)
#Complete the order
web_driver.find_element_by_id(checkout_continue_button_id).click()
print ("we believe we have placed your order. Please verify, and if this worked enjoy your new card :).")
def main():
user_selections = get_user_info()
firefox_instance = open_browser()
print ("Please log in. The author of this script didn't want to try to beat EVGA's captcha system. Once you are logged in, type literally anything into the console and press enter. Note that after this point, the entire process is automatic. DO NOT PROCEED IF YOU'RE NOT READY TO BUY THE CARD")
unused = input()
add_card_to_cart(user_selections["model_number"], firefox_instance)
#checkout(firefox_instance, user_selections)
if __name__ == "__main__":
main()