Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Commit

Permalink
Navigate to empty cart instead of error page to set driver cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
philippnormann committed Oct 27, 2020
1 parent 86d754b commit 21c7135
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions sniper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def main():
logging.info('API Token: ' + store_token)
logging.info('Overiding store cookies for driver...')
store_cookies = api_client.get_cookies(const.STORE_URL)
driver.get(const.STORE_URL)
driver.get(const.CART_URL)
for key, value in store_cookies.items():
driver.add_cookie({'name': key, 'value': value})
except SystemError:
Expand All @@ -201,7 +201,7 @@ async def main():
addded_to_cart = False
while not addded_to_cart:
try:
logging.info('Calling add to cart API...')
logging.info(f'Calling add to cart API for {target_id}...')
add_to_cart_response = await api_client.add_to_cart(store_token, target_id)
addded_to_cart = True
response = add_to_cart_response['message']
Expand All @@ -226,7 +226,7 @@ async def main():
if payment_method == 'credit-card':
checkout.checkout_guest(driver, timeout, customer, auto_submit)
else:
checkout.checkout_paypal(driver, timeout),
checkout.checkout_paypal(driver, timeout)

logging.info('Checkout successful!')
if notifications['checkout']['enabled']:
Expand Down
8 changes: 3 additions & 5 deletions sniper/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def get_product_page(driver, promo_locale, gpu):


def fill_out_shipping(driver, timeout, customer):
logging.info('Filling out shipping details...')
shipping_expanded = False
while not shipping_expanded:
try:
Expand Down Expand Up @@ -84,7 +83,7 @@ def fill_out_shipping(driver, timeout, customer):


def fill_out_form(driver, timeout, customer):
logging.info('Filling out form...')
logging.info('Filling out checkout form...')
driver.find_element(By.ID, 'billingName1').send_keys(
customer['billing']['first-name'])
driver.find_element(By.ID, 'billingName2').send_keys(
Expand Down Expand Up @@ -214,14 +213,13 @@ def checkout_guest(driver, timeout, customer, auto_submit=False):
except TimeoutException:
logging.info(
'Timed out waiting for checkout button to load, trying again...')
driver.get('https://store.nvidia.com/store/nvidia/cart')
driver.get(const.CART_URL)

fill_out_form(driver, timeout, customer)
driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')
driver.find_element(By.CSS_SELECTOR, const.SUBMIT_BUTTON_SELECTOR).click()

try:
logging.info('Skipping address check...')
driver.find_element(By.CLASS_NAME, 'dr_error')
skip_address_check(driver)
except NoSuchElementException:
Expand All @@ -242,4 +240,4 @@ def checkout_paypal(driver, timeout):
except TimeoutException:
logging.info(
'Timed out waiting for PayPal button to load, trying again...')
driver.get('https://store.nvidia.com/store/nvidia/cart')
driver.get(const.CART_URL)
1 change: 1 addition & 0 deletions sniper/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
STORE_HOST = 'store.nvidia.com'
STORE_URL = f'https://{STORE_HOST}/store'

CART_URL = f'{STORE_URL}/nvidia/cart'
TOKEN_URL = f'{STORE_URL}/nvidia/SessionToken'
CHECKOUT_URL = f'{STORE_URL}?Action=DisplayHGOP2LandingPage&SiteID=nvidia'

Expand Down

0 comments on commit 21c7135

Please sign in to comment.