sync: auto-sync from GURU-BEAST-ROG at 2026-05-22 14:57:57

Author: Mike Swanson
Machine: GURU-BEAST-ROG
Timestamp: 2026-05-22 14:57:57
This commit is contained in:
2026-05-22 14:57:58 -07:00
parent 66c65fa9bb
commit 68e523388a
2 changed files with 116 additions and 0 deletions

View File

@@ -16,6 +16,9 @@ Options:
--settle-ms N Extra wait after load for JS to render (default 1500)
--timeout-ms N Navigation timeout (default 25000)
--wait-until STATE domcontentloaded | load | networkidle (default: load)
--zip CODE Set delivery/location zip code for supported retailers
(Amazon, Best Buy). Defaults to 85715 (Tucson, AZ).
Pass empty string to skip: --zip ""
Exit codes: 0 ok, 2 navigation/render error, 3 bad usage.
Errors go to stderr; page content goes to stdout.
@@ -36,6 +39,8 @@ def main() -> int:
ap.add_argument("--timeout-ms", type=int, default=25000)
ap.add_argument("--wait-until", default="load",
choices=["domcontentloaded", "load", "networkidle"])
ap.add_argument("--zip", default="85715",
help="Delivery zip for Amazon/Best Buy (default: 85715). Pass empty to skip.")
args = ap.parse_args()
if not args.url.lower().startswith(("http://", "https://")):
@@ -70,6 +75,38 @@ def main() -> int:
)
page = ctx.new_page()
try:
# Pre-set delivery zip for supported retailers before loading the target URL.
if args.zip:
from urllib.parse import urlparse
host = urlparse(args.url).netloc.lower()
if "amazon.com" in host:
try:
# Load homepage so session cookies exist, then use the
# location picker UI (most reliable — no CSRF tokens needed).
page.goto("https://www.amazon.com", wait_until="load", timeout=15000)
page.wait_for_timeout(1200)
# Click the "Delivering to..." location widget in the nav bar.
page.click("#glow-ingress-block", timeout=6000)
page.wait_for_selector("#GLUXZipUpdateInput", timeout=6000)
page.fill("#GLUXZipUpdateInput", args.zip)
page.wait_for_timeout(300)
page.click('[data-action="GLUXPostalUpdateAction"]', timeout=5000)
page.wait_for_timeout(1000)
except Exception:
pass # non-fatal — continue to main URL
elif "bestbuy.com" in host:
try:
# Best Buy uses a GraphQL-backed zip picker; the query param approach
# is the most reliable headless method.
page.goto(
f"https://www.bestbuy.com/site/searchpage.jsp?st=test&postalCode={args.zip}",
wait_until="load",
timeout=10000,
)
page.wait_for_timeout(500)
except Exception:
pass # non-fatal
page.goto(args.url, wait_until=args.wait_until, timeout=args.timeout_ms)
if args.settle_ms > 0:
page.wait_for_timeout(args.settle_ms)