Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear Cache and Cookies with toggle #661

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ Options:
USE THIS OPTION AT YOUR OWN RISK!!!
NOTE: There is no functionality to choose payment
option, so bot may still fail during checkout

--clear-cache Clears the browser cache and cookies on startup. Default is false.

--help Show this message and exit.

Expand Down
8 changes: 8 additions & 0 deletions cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ def main():
default=False,
help="Wait if captcha could not be solved. Only occurs if enters captcha handler during checkout.",
)
@click.option(
"--clear-cache",
is_flag=True,
default=False,
help="Clear cache and cookies on initial load",
)
@notify_on_crash
def amazon(
no_image,
Expand All @@ -216,6 +222,7 @@ def amazon(
clean_credentials,
alt_offers,
captcha_wait,
clear_cache,
):
notification_handler.sound_enabled = not disable_sound
if not notification_handler.sound_enabled:
Expand Down Expand Up @@ -249,6 +256,7 @@ def amazon(
shipping_bypass=shipping_bypass,
alt_offers=alt_offers,
wait_on_captcha_fail=captcha_wait,
clear_cache=clear_cache,
)
try:
amzn_obj.run(delay=delay, test=test)
Expand Down
16 changes: 16 additions & 0 deletions stores/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(
shipping_bypass=False,
alt_offers=False,
wait_on_captcha_fail=False,
clear_cache=False,
):
self.notification_handler = notification_handler
self.asin_list = []
Expand Down Expand Up @@ -140,6 +141,7 @@ def __init__(
self.unknown_title_notification_sent = False
self.alt_offers = alt_offers
self.wait_on_captcha_fail = wait_on_captcha_fail
self.clear_cache = clear_cache

presence.enabled = not disable_presence

Expand Down Expand Up @@ -210,6 +212,20 @@ def run(self, delay=DEFAULT_REFRESH_DELAY, test=False):
self.show_config()

log.info("Waiting for home page.")

if self.clear_cache:
log.info("Clearing cache and cookies.")
send_command = ("POST", "/session/$sessionId/chromium/send_command")
self.driver.command_executor._commands["SEND_COMMAND"] = send_command
self.driver.execute(
"SEND_COMMAND", dict(cmd="Network.clearBrowserCache", params={})
)
time.sleep(1)
self.driver.execute(
"SEND_COMMAND", dict(cmd="Network.clearBrowserCookies", params={})
)
log.info("Cache and cookies cleared.")

while True:
try:
self.get_page(url=AMAZON_URLS["BASE_URL"])
Expand Down