From 271251c1f4a1b77c8711f0bbc79ef51aadf2ae34 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 17 Apr 2024 08:59:36 +0100 Subject: [PATCH] Fix login Closes: #2 --- backup.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/backup.py b/backup.py index a5877da..45fea0f 100644 --- a/backup.py +++ b/backup.py @@ -4,11 +4,11 @@ import configparser import os from datetime import date -from playwright.sync_api import Page, Playwright, sync_playwright # type: ignore +from playwright.sync_api import Page, Playwright, sync_playwright import_url = "https://www.goodreads.com/review/import" wait_mins = 10 -refresh_backup = False +refresh_backup = True today = date.today().isoformat() # current date in ISO format @@ -29,6 +29,7 @@ def login(page: Page) -> None: page.get_by_role("button", name="Sign in with email").click() page.get_by_label("Email").fill(config.get("login", "email")) page.get_by_label("Password").fill(config.get("login", "password")) + page.get_by_label("Keep me signed in").click() page.get_by_label("Sign in").click() @@ -39,12 +40,8 @@ def navigate_to_import_and_export(page: Page) -> None: page.get_by_role("link", name="Import and export").click() -def run(playwright: Playwright) -> None: - """Download export.""" - browser = playwright.chromium.launch(headless=True) - auth_json = os.path.join(script_dir, "auth.json") - context = browser.new_context(storage_state=auth_json) - page = context.new_page() +def run_backup(page: Page) -> None: + """Run backup.""" page.goto(import_url) if refresh_backup: @@ -67,9 +64,23 @@ def run(playwright: Playwright) -> None: save_to = os.path.join(backup_dir, f"{today}_goodreads_library_export.csv") download.save_as(save_to) + + +def run(playwright: Playwright) -> None: + """Download export.""" + browser = playwright.chromium.launch(headless=False) + auth_json = os.path.join(script_dir, "auth.json") + context = browser.new_context(storage_state=auth_json) + page = context.new_page() + + # login(page) + + page.goto("https://www.goodreads.com/") + + run_backup(page) + page.close() - # --------------------- context.storage_state(path=auth_json) context.close() browser.close()