Quellcode durchsuchen

fix: ita query dialog close

hujiarui vor 1 Monat
Ursprung
Commit
480115c6b5
1 geänderte Dateien mit 47 neuen und 2 gelöschten Zeilen
  1. 47 2
      plugins/ita_plugin.py

+ 47 - 2
plugins/ita_plugin.py

@@ -1801,6 +1801,8 @@ class ItaPlugin(IPlugin):
 
     def query(self, apt_type):
         self._raise_if_inspection_held()
+        routing_key = getattr(apt_type, "routing_key", str(apt_type))
+        self._log(f"Starting query for {routing_key}...")
         try:
             if self.free_config.get("query_mode", CALENDAR_QUERY_MODE) != CALENDAR_QUERY_MODE:
                 raise BizLogicError("Italy Query requires query_mode=calendar")
@@ -1809,6 +1811,7 @@ class ItaPlugin(IPlugin):
             route = self._resolve_route(apt_type)
             if self._prepared_calendar is None or same_origin_path(self.page.url) != CALENDAR_PATH:
                 if not self._enter_service(route):
+                    self._log(f"No slots found for {routing_key} (service reported no availability).")
                     return QueryResult(success=False, apt_type=apt_type,
                                          availability_status=AvailabilityStatus.NoneAvailable)
                 self._prepared_calendar = None
@@ -1820,11 +1823,12 @@ class ItaPlugin(IPlugin):
             probes = scan_until_first_available_month(self, route)
             available = next((days for days in probes if days), ())
             if not available:
+                self._log(f"No slots found for {routing_key} across scanned calendar months.")
                 return QueryResult(
                     success=False, apt_type=apt_type,
                     availability_status=AvailabilityStatus.NoneAvailable)
             earliest = datetime.combine(available[0].day, datetime.min.time())
-            self._log(f"Italy Calendar earliest_date={earliest.date().isoformat()}")
+            self._log(f"Found available slots for {routing_key}! Earliest date: {earliest.date().isoformat()}")
             return QueryResult(
                 success=True, apt_type=apt_type,
                 availability_status=AvailabilityStatus.Available,
@@ -1850,10 +1854,48 @@ class ItaPlugin(IPlugin):
                 self._capture.write()
             raise error from exc
 
+    def _dismiss_jconfirm(self, timeout=2) -> bool:
+        if not self.page:
+            return False
+        try:
+            btn = (
+                self.page.ele("css:.jconfirm-buttons button", timeout=timeout)
+                or self.page.ele("css:.jconfirm-box button", timeout=0.5)
+                or self.page.ele("css:button.btn.btn-blue", timeout=0.5)
+            )
+            if btn:
+                self._log("Italy dismissing jconfirm dialog (clicking OK)...")
+                clicked = False
+                if getattr(self, "mouse", None):
+                    try:
+                        self.mouse.human_click_ele(btn)
+                        clicked = True
+                    except Exception as err:
+                        self._log(f"human_click_ele on jconfirm button failed: {err}")
+                if not clicked:
+                    try:
+                        btn.click()
+                        clicked = True
+                    except Exception:
+                        pass
+                if not clicked:
+                    self.page.run_js("arguments[0].click();", btn)
+                time.sleep(0.5)
+                if self.page.ele("css:.jconfirm-box", timeout=0.5):
+                    self.page.run_js(
+                        "const b = document.querySelector('.jconfirm-buttons button, .jconfirm-box button'); if (b) b.click();"
+                    )
+                    time.sleep(0.3)
+                return True
+        except Exception as exc:
+            self._log(f"Italy dismissing jconfirm non-fatal: {exc}")
+        return False
+
     def _enter_service(self, route) -> bool:
         booking_path = self._booking_path(route)
         self.page.get(f"{self.ita_url}/Services")
         self.page.wait.doc_loaded()
+        self._dismiss_jconfirm(timeout=1)
         capture = _capture(self)
         capture.start()
         if self._authenticated_path() != "/Services":
@@ -1863,13 +1905,14 @@ class ItaPlugin(IPlugin):
             raise NotFoundError(f"Italy service link is missing: {booking_path}")
         click_started_at = datetime.now(timezone.utc).isoformat()
         try:
+            self._log(f"Entering service {booking_path}...")
             self.mouse.human_click_ele(link)
             self.page.wait.load_start()
             self.page.wait.doc_loaded()
             path = self._authenticated_path()
             if path == "/Services":
                 marker = self.page.ele("#WlNotAvailable", timeout=1)
-                notice = self.page.ele(".jconfirm-content", timeout=1)
+                notice = self.page.ele(".jconfirm-content", timeout=2)
                 marker_text = (marker.attr("value") if marker else "") or ""
                 notice_text = (notice.text if notice else "") or ""
                 text = (marker_text or notice_text).strip().casefold()
@@ -1889,6 +1932,8 @@ class ItaPlugin(IPlugin):
         if path == "/Services":
             if no_availability:
                 capture.write()
+                self._log("Service confirmed: posti disponibili esauriti (no slots).")
+                self._dismiss_jconfirm()
                 return False  # The service explicitly reports no availability.
             raise BizLogicError(
                 "Italy service returned an unknown response",