sync
This commit is contained in:
@@ -27,7 +27,9 @@ CHROMIUM_PATH=/usr/bin/chromium gunicorn --workers 1 --threads 2 --bind 127.0.0.
|
|||||||
|
|
||||||
Na świat wystaw aplikację przez nginx/Caddy z HTTPS. Zostaw jeden worker: aplikacja celowo dopuszcza tylko jedno sprawdzenie naraz, by chronić RAM i CPU RPi.
|
Na świat wystaw aplikację przez nginx/Caddy z HTTPS. Zostaw jeden worker: aplikacja celowo dopuszcza tylko jedno sprawdzenie naraz, by chronić RAM i CPU RPi.
|
||||||
|
|
||||||
Google może czasem pokazać niezalogowanej przeglądarce „ograniczony widok” i ukryć wszystkie opinie. Wtedy aplikacja zwraca błąd — nigdy nie zgaduje wartości z długości pasków i nie wymaga przechowywania konta Google.
|
Google może czasem pokazać niezalogowanej przeglądarce „ograniczony widok” i ukryć wszystkie opinie. Wtedy aplikacja zwraca błąd — nigdy nie zgaduje wartości z długości pasków.
|
||||||
|
|
||||||
|
Jeśli ograniczony widok pojawia się stale, można utworzyć osobny profil Chromium, zalogować go ręcznie i ustawić `CHROMIUM_PROFILE_PATH`. Profil przechowuje sesję przeglądarki; aplikacja nadal nie zapisuje opinii.
|
||||||
|
|
||||||
## Testy
|
## Testy
|
||||||
|
|
||||||
|
|||||||
+19
-3
@@ -105,9 +105,23 @@ def get_rating_distribution(url: str) -> dict:
|
|||||||
launch = {"headless": True, "args": ["--disable-dev-shm-usage", "--no-first-run", "--disable-gpu"]}
|
launch = {"headless": True, "args": ["--disable-dev-shm-usage", "--no-first-run", "--disable-gpu"]}
|
||||||
if os.environ.get("CHROMIUM_PATH"):
|
if os.environ.get("CHROMIUM_PATH"):
|
||||||
launch["executable_path"] = os.environ["CHROMIUM_PATH"]
|
launch["executable_path"] = os.environ["CHROMIUM_PATH"]
|
||||||
browser = playwright.chromium.launch(**launch)
|
profile_path = os.environ.get("CHROMIUM_PROFILE_PATH")
|
||||||
|
browser = None
|
||||||
|
if profile_path:
|
||||||
|
# A headless systemd service has no desktop keyring. Use this only
|
||||||
|
# with the dedicated, permission-restricted application profile.
|
||||||
|
launch["args"].append("--password-store=basic")
|
||||||
|
context = playwright.chromium.launch_persistent_context(
|
||||||
|
user_data_dir=profile_path,
|
||||||
|
locale="pl-PL",
|
||||||
|
viewport={"width": 1100, "height": 800},
|
||||||
|
**launch,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
browser = playwright.chromium.launch(**launch)
|
||||||
|
context = browser.new_context(locale="pl-PL", viewport={"width": 1100, "height": 800})
|
||||||
try:
|
try:
|
||||||
page = browser.new_page(locale="pl-PL", viewport={"width": 1100, "height": 800})
|
page = context.pages[0] if context.pages else context.new_page()
|
||||||
page.goto(url, wait_until="domcontentloaded", timeout=30_000)
|
page.goto(url, wait_until="domcontentloaded", timeout=30_000)
|
||||||
_accept_cookies(page)
|
_accept_cookies(page)
|
||||||
_open_reviews(page)
|
_open_reviews(page)
|
||||||
@@ -126,7 +140,9 @@ def get_rating_distribution(url: str) -> dict:
|
|||||||
average = round(sum(int(stars) * count for stars, count in ratings.items()) / total, 2) if total else 0
|
average = round(sum(int(stars) * count for stars, count in ratings.items()) / total, 2) if total else 0
|
||||||
return {"total": total, "average": average, "ratings": ratings}
|
return {"total": total, "average": average, "ratings": ratings}
|
||||||
finally:
|
finally:
|
||||||
browser.close()
|
context.close()
|
||||||
|
if browser:
|
||||||
|
browser.close()
|
||||||
except ScrapeError:
|
except ScrapeError:
|
||||||
raise
|
raise
|
||||||
except PlaywrightTimeoutError:
|
except PlaywrightTimeoutError:
|
||||||
|
|||||||
Reference in New Issue
Block a user