Fix login

Closes: #2
This commit is contained in:
Edward Betts 2024-04-17 08:59:36 +01:00
parent b678e6fa68
commit 271251c1f4

View file

@ -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()