"""AAO Career Center adapter — click-based AJAX pagination.""" from __future__ import annotations from loguru import logger from gimme_job.adapters.base import ManifestDrivenAdapter from gimme_job.adapters.registry import register from gimme_job.models.dto import JobPostingCandidate, RawJobCard @register("aaoinfo") class AAOInfoAdapter(ManifestDrivenAdapter): _BASE_URL = "https://careers.aaoinfo.org" def _wait_for_results(self, page) -> None: try: page.wait_for_selector("div.job-tile", timeout=15000, state="attached") except Exception: logger.debug("[aaoinfo] Results wait timed out — may be zero results") def collect_cards(self, page, manifest): self._wait_for_results(page) return super().collect_cards(page, manifest) def paginate(self, page, page_index: int, config) -> bool: """Click the next page number button in the AJAX pagination.""" if page_index >= config.pagination.max_pages - 1: return False next_page = page_index + 2 # Try clicking the specific page number button next_btn = page.query_selector(f"#page-item-{next_page} a") if not next_btn: # Fall back to the last non-active/non-disabled pagination link next_btn = page.query_selector( "ul.pagination li.page-item:not(.active):not(.disabled):last-child a" ) if not next_btn: logger.debug(f"[aaoinfo] No next page button found — stopping at page {page_index + 1}") return False logger.debug(f"[aaoinfo] Paginating to page {next_page}") next_btn.click() # Wait for the new page's active indicator to confirm AJAX completed try: page.wait_for_selector(f"#page-item-{next_page}.active", timeout=12000) except Exception: page.wait_for_timeout(3000) return True def normalize(self, raw: RawJobCard) -> JobPostingCandidate: candidate = super().normalize(raw) if candidate.job_url and candidate.job_url.startswith("/"): candidate.job_url = self._BASE_URL + candidate.job_url return candidate