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

More customization for address check since some folks would like to u… #53

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e6d7c41
More customisation for address check since some folks would like to u…
hwamil Oct 3, 2020
a2ec838
Made if statements more readable
hwamil Oct 3, 2020
7d4ebd4
Made it a little cleaner by throwing the parameters into customer.jso…
hwamil Oct 6, 2020
9029885
Changed \t into \s for formatting
hwamil Oct 6, 2020
3a1c799
Merge branch 'skipAddressCheck' of https://github.com/hwamil/nvidia-s…
hwamil Oct 6, 2020
cfa5519
Usage update on 'force' param in customer['billing'] and customer['sh…
hwamil Oct 6, 2020
1ba4449
formatting
hwamil Oct 6, 2020
34ba63f
Prevent crash if user does not update customer.json
hwamil Oct 7, 2020
951ea26
checkpoint
hwamil Oct 27, 2020
58b6455
tested and working with no conflicts after merging with main branch
hwamil Oct 27, 2020
3847b61
Added changes so that if user deletes shipping parameter from custome…
hwamil Oct 27, 2020
26df435
Made it so that it tries shippingOptionID2 before resorting to defaul…
hwamil Oct 27, 2020
bdc4941
Fixed broken code. Sorry for pushing before testing :(
hwamil Oct 27, 2020
a16df18
More fixes
hwamil Oct 27, 2020
7380c13
deleted extra parens
hwamil Oct 27, 2020
58bdf5c
Attempts at clicking submit order button continues forever instead of…
hwamil Oct 27, 2020
ec9b554
checkpoint
hwamil Oct 27, 2020
babebf7
got rid of maximize window at submit_order
hwamil Oct 27, 2020
f4bfb61
Gotten rid of selection shippingOptionID2 as the options seem to be c…
hwamil Oct 27, 2020
65746ac
fix
hwamil Oct 27, 2020
651195c
fixed nosuchelement exception
hwamil Oct 27, 2020
2f2d821
Merge branch 'master' of https://github.com/philippnormann/nvidia-sni…
hwamil Oct 28, 2020
d79b474
asdf
hwamil Oct 28, 2020
594113e
adsf
hwamil Oct 28, 2020
7ac2048
solved merge conflicts
hwamil Oct 28, 2020
781f409
added click for "use this address" button
hwamil Oct 28, 2020
ab8adf9
Merge branch 'skipAddressCheck' of https://github.com/hwamil/nvidia-s…
hwamil Oct 28, 2020
a450721
added back `select_shipping_speed()` which got deleted somehow
hwamil Oct 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ There has been a common issue related to shipping speeds not being available whe
- `true`: (Default) Fallback to using the standard shipping speed when the desired speed isn't available
- `false`: Stop the bot from continuing with checkout

### `force`
Toggling this option forces sniper to use the address(es) in customer.json instead of the one suggested by Digital River during the checkout process.
- `true`: Use address(es) in customer.json
- `false`: (Default) Use address(es) suggested by Digital River

### `country`
The `country` field can have the following values:
- `AT`: Austria
Expand Down
Binary file added config/.DS_Store
Binary file not shown.
8 changes: 5 additions & 3 deletions config/customer_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"post-code": "95051",
"country": "US",
"email": "[email protected]",
"phone": "408-486-2000"
"phone": "408-486-2000",
"force": false
},
"shipping": {
"first-name": "Lisa",
Expand All @@ -23,7 +24,8 @@
"country": "US",
"phone": "89-4505-3199",
"speed": "shippingOptionID2",
"backup-speed": true
"backup-speed": true,
"force": false
},
"credit": {
"card": "4111111111111111",
Expand All @@ -33,4 +35,4 @@
},
"code": "737"
}
}
}
Binary file added geckodriver
Binary file not shown.
Binary file added sniper/__init__.pyc
Binary file not shown.
57 changes: 35 additions & 22 deletions sniper/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def fill_out_form(driver, timeout, customer):
driver.find_element(By.ID, 'verEmail').send_keys(
customer['billing']['email'])

fill_out_shipping(driver, timeout, customer)
if 'shipping' in customer:
fill_out_shipping(driver, timeout, customer)

driver.find_element(By.ID, 'ccNum').send_keys(
customer['credit']['card'])
Expand All @@ -136,30 +137,35 @@ def fill_out_form(driver, timeout, customer):
customer['credit']['code'])


def skip_address_check(driver):
logging.info('Skipping address check...')
def skip_address_check(driver, customer):
try:
driver.find_element(By.ID, 'billingAddressOptionRow2').click()
except NoSuchElementException:
pass
if customer['billing']['force']:
driver.find_element(By.ID, 'billingAddressOptionRow2').click()
else:
driver.find_element(By.ID, 'billingAddressOptionRow1').click()
except KeyError:
driver.find_element(By.ID, 'billingAddressOptionRow1').click()
try:
driver.find_element(By.ID, 'shippingAddressOptionRow2').click()
except NoSuchElementException:
pass
if customer['shipping']['force']:
driver.find_element(By.ID, 'shippingAddressOptionRow2').click()
else:
driver.find_element(By.ID, 'shippingAddressOptionRow1').click()
except KeyError:
driver.find_element(By.ID, 'shippingAddressOptionRow1').click()
driver.find_element(By.ID, 'selectionButton').click()


def select_shipping_speed(driver, timeout, customer):
try:
shipping_speed = customer['shipping']['speed']
WebDriverWait(driver, timeout).until(
EC.presence_of_element_located((By.ID, shipping_speed)))
speed_button = EC.element_to_be_clickable((By.ID, shipping_speed))
WebDriverWait(driver, timeout).until(speed_button)
driver.find_element(By.ID, shipping_speed).click()
except TimeoutException:
logging.warning(f'Could not find shipping speed {shipping_speed}')
if 'backup-speed' in customer['shipping']:
if customer['shipping']['backup-speed']:
logging.info('Continuing with default speed')
logging.info('continuing with default speed')
else:
logging.info(
'User opted to stop if shipping speed not found.')
Expand All @@ -168,6 +174,11 @@ def select_shipping_speed(driver, timeout, customer):
logging.warning(
'data/customer.json missing "backup-speed" option under "shipping", '
'continuing with default speed')
except KeyError:
logging.warning('Could not find shipping param in customer.json')
logging.info('continuing with default speed.')
except NoSuchElementException:
logging.info(f'Error while attempting to interact with element {shipping_speed}. Continuing with default speed')


def click_recaptcha(driver, timeout):
Expand All @@ -184,15 +195,16 @@ def click_recaptcha(driver, timeout):


def submit_order(driver, timeout):
try:
submit_clickable = EC.element_to_be_clickable(
(By.CSS_SELECTOR, const.SUBMIT_BUTTON_SELECTOR))
WebDriverWait(driver, timeout).until(submit_clickable)
driver.find_element(
By.CSS_SELECTOR, const.SUBMIT_BUTTON_SELECTOR).click()
return True
except (ElementClickInterceptedException, TimeoutException):
return False
while True:
try:
submit_clickable = EC.element_to_be_clickable(
(By.CSS_SELECTOR, const.SUBMIT_BUTTON_SELECTOR))
WebDriverWait(driver, timeout).until(submit_clickable)
driver.find_element(
By.CSS_SELECTOR, const.SUBMIT_BUTTON_SELECTOR).click()
return True
except (ElementClickInterceptedException, TimeoutException):
logging.info('Waiting for the submit button to be activated')


def checkout_guest(driver, timeout, customer, auto_submit=False):
Expand Down Expand Up @@ -222,13 +234,14 @@ def checkout_guest(driver, timeout, customer, auto_submit=False):
try:
error = driver.find_element(By.CLASS_NAME, 'dr_error')
if len(error.text) > 0:
skip_address_check(driver)
skip_address_check(driver, customer)
except NoSuchElementException:
pass

select_shipping_speed(driver, timeout, customer)



def checkout_paypal(driver, timeout):
proceeded_to_paypal = False
logging.info('Checking out using PayPal Express...')
Expand Down