Set browser locale/timezone defaults to de-DE and Europe/Berlin
This commit is contained in:
parent
513a28539d
commit
390ffe1d40
2 changed files with 29 additions and 2 deletions
|
|
@ -24,6 +24,12 @@ python -m playwright install chromium
|
|||
python main.py configure --marketplace de --download-dir "C:\Users\<USER>\Downloads\amazon_rechnungen"
|
||||
```
|
||||
|
||||
Explizit fuer Deutschland (Sprache/Zeitzone):
|
||||
|
||||
```powershell
|
||||
python main.py configure --marketplace de --locale de-DE --timezone Europe/Berlin --currency EUR --download-dir "C:\Users\<USER>\Downloads\amazon_rechnungen"
|
||||
```
|
||||
|
||||
Dann oeffnet sich ein Browser. Dort bei Amazon anmelden und auf Enter im Terminal druecken.
|
||||
Die Session wird lokal gespeichert in:
|
||||
|
||||
|
|
@ -113,6 +119,7 @@ Optionen:
|
|||
- `--headless true|false`: Browser sichtbar oder unsichtbar
|
||||
- `--debug`: zeigt, wie viele Detailseiten und Rechnungslinks gefunden werden
|
||||
- `--debug-json [pfad]`: schreibt Laufdetails als JSON (ohne Pfad: Standarddatei)
|
||||
- `configure --locale de-DE --timezone Europe/Berlin`: erzwingt deutsche Sprache und Berliner Zeitzone im Browser-Kontext
|
||||
|
||||
## Hinweise
|
||||
|
||||
|
|
|
|||
24
main.py
24
main.py
|
|
@ -50,6 +50,18 @@ def save_config(config: dict) -> None:
|
|||
CONFIG_PATH.write_text(json.dumps(config, indent=2), encoding="utf-8")
|
||||
|
||||
|
||||
def build_context_options(config: dict) -> dict:
|
||||
locale = config.get("locale", "de-DE")
|
||||
timezone = config.get("timezone", "Europe/Berlin")
|
||||
return {
|
||||
"locale": locale,
|
||||
"timezone_id": timezone,
|
||||
"extra_http_headers": {
|
||||
"Accept-Language": "de-DE,de;q=0.9,en;q=0.8",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def parse_iso_date(value: str) -> date:
|
||||
try:
|
||||
return datetime.strptime(value, "%Y-%m-%d").date()
|
||||
|
|
@ -269,13 +281,16 @@ def configure(args) -> None:
|
|||
"marketplace": args.marketplace,
|
||||
"download_dir": str(Path(args.download_dir).expanduser().resolve()),
|
||||
"headless": args.headless,
|
||||
"locale": args.locale,
|
||||
"timezone": args.timezone,
|
||||
"currency": args.currency,
|
||||
}
|
||||
save_config(config)
|
||||
ensure_app_dir()
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=False)
|
||||
context = browser.new_context()
|
||||
context = browser.new_context(**build_context_options(config))
|
||||
page = context.new_page()
|
||||
page.goto(f"https://www.amazon.{args.marketplace}/your-orders/orders", wait_until="domcontentloaded")
|
||||
print("Bitte im Browser bei Amazon einloggen.")
|
||||
|
|
@ -312,7 +327,9 @@ def download(args) -> None:
|
|||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=args.headless if args.headless is not None else bool(config.get("headless", True)))
|
||||
context = browser.new_context(storage_state=str(STORAGE_STATE_PATH))
|
||||
context_options = build_context_options(config)
|
||||
context_options["storage_state"] = str(STORAGE_STATE_PATH)
|
||||
context = browser.new_context(**context_options)
|
||||
page = context.new_page()
|
||||
|
||||
base_orders_url = f"https://www.amazon.{marketplace}/your-orders/orders"
|
||||
|
|
@ -465,6 +482,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|||
p_config.add_argument("--marketplace", default="de", help="z. B. de, com, co.uk")
|
||||
p_config.add_argument("--download-dir", default="~/Downloads/amazon_rechnungen")
|
||||
p_config.add_argument("--headless", action="store_true", help="Standard fuer Download-Lauf im Headless-Mode")
|
||||
p_config.add_argument("--locale", default="de-DE", help="Browser-Locale, z. B. de-DE")
|
||||
p_config.add_argument("--timezone", default="Europe/Berlin", help="Zeitzone, z. B. Europe/Berlin")
|
||||
p_config.add_argument("--currency", default="EUR", help="Waehrungshinweis fuer Konfiguration")
|
||||
p_config.add_argument(
|
||||
"--login-wait-seconds",
|
||||
type=int,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue