From ee07f373eab793e0853f0203c35a75975ba88c19 Mon Sep 17 00:00:00 2001 From: Vysyr Date: Mon, 31 Aug 2026 21:02:52 +0200 Subject: [PATCH] sync --- scraper.py | 6 ++-- templates/index.html | 6 ++-- tests/test_app.py | 77 -------------------------------------------- 3 files changed, 6 insertions(+), 83 deletions(-) delete mode 100644 tests/test_app.py diff --git a/scraper.py b/scraper.py index 045db51..a36d0ad 100644 --- a/scraper.py +++ b/scraper.py @@ -136,16 +136,16 @@ def get_rating_distribution( browser = playwright.chromium.launch(**launch) context = browser.new_context(locale="pl-PL", viewport={"width": 1100, "height": 800}) try: - report(50, "Otwarto Chromium") + report(50, "Trwa łączenie z Google Maps") page = context.pages[0] if context.pages else context.new_page() context.add_init_script( "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})" ) page.goto(url, wait_until="domcontentloaded", timeout=30_000) _accept_cookies(page) - report(75, "Załadowano Google Maps") + report(75, "Ładowanie opinii") _open_reviews(page) - report(90, "Otwarto panel opinii") + report(90, "Obliczanie statystyk") page.wait_for_timeout(700) labels = page.locator("[aria-label]").evaluate_all( "els => els.map(el => el.getAttribute('aria-label')).filter(Boolean)" diff --git a/templates/index.html b/templates/index.html index f86cdde..ece5022 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,14 +3,14 @@ - Rozkład opinii Google + Licznik opinii Google

Google Maps

-

Policz opinie według oceny

-

Wklej link do firmy lub miejsca. Aplikacja niczego nie zapisuje.

+

Extra licznik opinii 9000

+

Wklej link do firmy lub miejsca z Google Maps.

diff --git a/tests/test_app.py b/tests/test_app.py deleted file mode 100644 index 01cc4fa..0000000 --- a/tests/test_app.py +++ /dev/null @@ -1,77 +0,0 @@ -import unittest -import time -from unittest.mock import patch - -from app import app -from scraper import parse_distribution_labels, validate_maps_url - - -class ValidationTests(unittest.TestCase): - def test_accepts_google_maps_links(self): - urls = [ - "https://maps.app.goo.gl/USRCto35jhoVtmj4A", - "https://www.google.com/maps/place/Test/@50,20,15z", - "https://maps.google.pl/maps?q=test", - ] - for url in urls: - with self.subTest(url=url): - self.assertTrue(validate_maps_url(url).startswith("https://")) - - def test_rejects_unsafe_links(self): - urls = [ - "http://maps.app.goo.gl/USRCto35jhoVtmj4A", - "https://evil.example/maps/x", - "https://google.com.evil.example/maps/x", - "https://user:pass@www.google.com/maps/x", - "https://www.google.com:444/maps/x", - "https://www.google.com/search?q=x", - "file:///etc/passwd", - ] - for url in urls: - with self.subTest(url=url), self.assertRaises(ValueError): - validate_maps_url(url) - - def test_parses_exact_accessibility_labels(self): - labels = [ - "5 gwiazdek, 1 234 opinie", "4 gwiazdki, 56 opinii", - "3 stars, 7 reviews", "2 stars, 1 review", "1 gwiazdka, 0 opinii", - ] - self.assertEqual(parse_distribution_labels(labels), {5: 1234, 4: 56, 3: 7, 2: 1, 1: 0}) - - -class ApiTests(unittest.TestCase): - def test_home_page(self): - self.assertEqual(app.test_client().get("/").status_code, 200) - - def test_rejects_non_google_url(self): - response = app.test_client().post("/api/reviews", json={"url": "https://example.com/"}) - self.assertEqual(response.status_code, 400) - - def test_rejects_large_request(self): - response = app.test_client().post("/api/reviews", data=b"x" * 5000, content_type="application/json") - self.assertEqual(response.status_code, 413) - - def test_reports_job_progress_and_result(self): - expected = {"total": 3, "average": 4.0, "ratings": {"5": 2, "4": 0, "3": 0, "2": 0, "1": 1}} - - def fake_scrape(_url, progress): - progress(50, "Otwarto Chromium") - progress(99, "Pojawiły się liczniki") - return expected - - client = app.test_client() - with patch("app.get_rating_distribution", side_effect=fake_scrape): - start = client.post("/api/reviews", json={"url": "https://maps.app.goo.gl/USRCto35jhoVtmj4A"}) - self.assertEqual(start.status_code, 202) - job_id = start.get_json()["job_id"] - for _ in range(100): - job = client.get(f"/api/reviews/{job_id}").get_json() - if job["status"] == "complete": - break - time.sleep(0.005) - self.assertEqual(job["progress"], 100) - self.assertEqual(job["result"], expected) - - -if __name__ == "__main__": - unittest.main()