Skip to content

Commit

Permalink
Merge pull request #440 from Hari-Nagarajan/hotfix
Browse files Browse the repository at this point in the history
Hot fix 0.5.3
  • Loading branch information
DakkJaniels authored Dec 23, 2020
2 parents b5ff968 + 8cbdec4 commit 144983f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
5 changes: 1 addition & 4 deletions cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ def amazon(
slow_mode,
p,
):
if no_image:
selenium_utils.no_amazon_image()
else:
selenium_utils.yes_amazon_image()

notification_handler.sound_enabled = not disable_sound
if not notification_handler.sound_enabled:
Expand All @@ -162,6 +158,7 @@ def amazon(
disable_presence=disable_presence,
slow_mode=slow_mode,
encryption_pass=p,
no_image=no_image,
)
try:
amzn_obj.run(delay=delay, test=test)
Expand Down
31 changes: 28 additions & 3 deletions stores/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"Currently, there are no sellers that can deliver this item to your location.",
"There are currently no listings for this search. Try a different refinement.",
"There are currently no listings for this search. Try a different refinement.",
"There are currently no listings for this product in . Try changing the condition type.",
]

# OFFER_PAGE_TITLES = ["Amazon.com: Buying Choices:"]
Expand Down Expand Up @@ -191,6 +192,7 @@ def __init__(
disable_presence=False,
slow_mode=False,
encryption_pass=None,
no_image=False,
):
self.notification_handler = notification_handler
self.asin_list = []
Expand All @@ -211,6 +213,7 @@ def __init__(
self.slow_mode = slow_mode
self.setup_driver = True
self.headless = headless
self.no_image = no_image

presence.enabled = not disable_presence
presence.start_presence()
Expand Down Expand Up @@ -522,6 +525,7 @@ def check_stock(self, asin, reserve_min, reserve_max, retry=0):
)
fail_counter = 0
presence.searching_update()

while True:
try:
self.get_page(f.url)
Expand Down Expand Up @@ -1013,7 +1017,7 @@ def save_page_source(self, page):
f.write(page_source)

def wait_for_page_change(self, page_title, timeout=3):
time_to_end = time.time() + timeout
time_to_end = self.get_timeout(timeout=timeout)
while time.time() < time_to_end and (
self.driver.title == page_title or not self.driver.title
):
Expand Down Expand Up @@ -1044,13 +1048,30 @@ def get_webdriver_pids(self):
self.webdriver_child_pids.append(child.pid)

def get_page(self, url):
current_page = self.driver.title
check_cart_element = []
current_page = []
try:
check_cart_element = self.driver.find_element_by_xpath(
'//*[@id="nav-cart"]'
)
except exceptions.NoSuchElementException:
current_page = self.driver.title
try:
self.driver.get(url=url)
except exceptions.WebDriverException or exceptions.TimeoutException:
log.error(f"failed to load page at url: {url}")
return False
if self.wait_for_page_change(current_page):
if check_cart_element:
timeout = self.get_timeout()
while True:
try:
check_cart_element.is_displayed()
except exceptions.StaleElementReferenceException:
break
if time.time() > timeout:
return False
return True
elif self.wait_for_page_change(current_page):
return True
else:
log.error("page did not change")
Expand Down Expand Up @@ -1102,6 +1123,10 @@ def create_driver(self):
"profile.password_manager_enabled": False,
"credentials_enable_service": False,
}
if self.no_image:
prefs["profile.managed_default_content_settings.images"] = 2
else:
prefs["profile.managed_default_content_settings.images"] = 0
options.add_experimental_option("prefs", prefs)
options.add_argument(f"user-data-dir=.profile-amz")
if not self.slow_mode:
Expand Down
10 changes: 0 additions & 10 deletions utils/selenium_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ def __call__(self, driver):
pass


def no_amazon_image():
prefs = {"profile.managed_default_content_settings.images": 2}
options.add_experimental_option("prefs", prefs)


def yes_amazon_image():
prefs = {"profile.managed_default_content_settings.images": 0}
options.add_experimental_option("prefs", prefs)


def wait_for_element(d, e_id, time=30):
"""
Uses webdriver(d) to wait for page title(title) to become visible
Expand Down
2 changes: 1 addition & 1 deletion utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

LATEST_URL = "https://api.github.com/repos/Hari-Nagarajan/fairgame/releases/latest"

version = "0.5.2"
version = "0.5.3"


def check_version():
Expand Down

0 comments on commit 144983f

Please sign in to comment.