Skip to content

Commit

Permalink
Updated logging to look nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
ssspe committed Sep 16, 2018
1 parent 67853a1 commit da46ae0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/dominos_orderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def change_crust(webdriver, crust):
if const.CRUSTS[crust]:
webdriver.find_element_by_xpath("//i[@class#'icon-chevron-right carousel-control-icon is-clickable']")
webdriver.find_element_by_xpath(f"//p[contains(text(), '{crust}')]").click()
logging.info(f" {crust}")


def click_topping(webdriver, topping):
Expand Down Expand Up @@ -64,6 +65,7 @@ def customise_pizza(webdriver, pizza_index, pizza, resource_name):
"""

is_customised = True
logging.info(f"Adding pizza {pizza['name']}!")

webdriver.find_elements_by_xpath(f"//button[@resource-name='{resource_name}']")[
pizza_index.index(pizza['name'])].click()
Expand All @@ -73,15 +75,17 @@ def customise_pizza(webdriver, pizza_index, pizza, resource_name):
change_crust(webdriver, pizza['customisation']['crust'])

for topping in pizza['customisation']['extra']:
if not click_topping(webdriver, topping):
is_customised = False
logging.info(f"Added {topping} to the pizza.")

for topping in pizza['customisation']['remove']:
for clicks in range(2):
if topping != "":
if not click_topping(webdriver, topping):
is_customised = False
logging.info(f"Removed {topping} from the pizza.")
logging.info(f" + {topping}")

for topping in pizza['customisation']['remove']:
if topping != "":
for clicks in range(2):
if not click_topping(webdriver, topping):
is_customised = False
logging.info(f" - {topping}")

if not is_customised:
error_restart(webdriver)
Expand Down Expand Up @@ -122,15 +126,14 @@ def process_pizza_json(webdriver):
pizza_index = [pizza_text.text for pizza_text in pizzas]

if pizza['customise']:
logging.info(f"Customizing pizza {pizza['name']}!")

if pizza['name'] in pizza_index:
customise_pizza(webdriver, pizza_index, pizza, "Customise")
scroll_to_top(webdriver) # Add to order is at the top of the page
webdriver.find_element_by_id("add-to-order").click()

else:
if pizza['name'] in pizza_index:
logging.info(f"Adding pizza {pizza['name']}!")
# Adding the pizza that is at the index of the pizza name to the basket
webdriver.find_elements_by_xpath("//button[@resource-name='AddToBasket']")[
pizza_index.index(pizza['name'])].click()
Expand Down Expand Up @@ -162,7 +165,6 @@ def process_pizza_json(webdriver):
pizza_index = [pizza.text for pizza in pizzas]

if pizza['name'] in pizza_index:
logging.info(f"Customizing pizza {pizza['name']}!")
customise_pizza(webdriver, pizza_index, pizza, "Choose")

if first_half:
Expand Down
2 changes: 1 addition & 1 deletion src/web_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ def scroll_to_top(webdriver):
:param webdriver: The Selenium webdriver
"""
webdriver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.HOME)
time.sleep(5) # Have to sleep to allow dominos server to catch up
time.sleep(10) # Have to sleep to allow dominos server to catch up

0 comments on commit da46ae0

Please sign in to comment.