| 1 | """IBM: the search API behind ``www.ibm.com/careers/search``. |
| 2 | |
| 3 | IBM's careers site (``careers.ibm.com``) answers automated requests with an |
| 4 | empty 202, sitemaps included. Its search page loads the roles in the browser |
| 5 | from ``www-api.ibm.com/search/api/v2``, which answers up to 100 a call with |
| 6 | each role's title, team, location and the opening of its text, and the |
| 7 | board's total. No field is a posting date, so no row claims one. |
| 8 | """ |
| 9 | |
| 10 | from __future__ import annotations |
| 11 | |
| 12 | from typing import Any, Callable |
| 13 | |
| 14 | from .. import http, jobs |
| 15 | |
| 16 | PROVIDER_IBM = "ibm" |
| 17 | PAGE_SIZE = 100 |
| 18 | SEARCH_URL = "https://www-api.ibm.com/search/api/v2" |
| 19 | |
| 20 | |
| 21 | def listing_url(entry: dict[str, Any] | None = None) -> str: |
| 22 | return SEARCH_URL |
| 23 | |
| 24 | |
| 25 | def search_body(offset: int) -> dict[str, Any]: |
| 26 | return { |
| 27 | "appId": "careers", |
| 28 | "scopes": ["careers2"], |
| 29 | "query": {"bool": {"must": []}}, |
| 30 | "size": PAGE_SIZE, |
| 31 | "from": offset, |
| 32 | "sort": [{"_score": "desc"}], |
| 33 | "lang": "zz", |
| 34 | "localeSelector": {}, |
| 35 | "sm": {"query": "", "lang": "zz"}, |
| 36 | "_source": [ |
| 37 | "_id", "title", "url", "description", "language", |
| 38 | "field_keyword_08", "field_keyword_17", "field_keyword_18", "field_keyword_19", |
| 39 | ], |
| 40 | } |
| 41 | |
| 42 | |
| 43 | def parse_listing(payload: Any) -> tuple[list[dict[str, Any]], int]: |
| 44 | hits = payload.get("hits") if isinstance(payload, dict) else None |
| 45 | rows = hits.get("hits") if isinstance(hits, dict) else None |
| 46 | if not isinstance(rows, list): |
| 47 | raise jobs.BoardShapeError("no hits") |
| 48 | total = hits.get("total") |
| 49 | total = int(total.get("value") or 0) if isinstance(total, dict) else jobs._reported_total(hits, "total") |
| 50 | items: list[dict[str, Any]] = [] |
| 51 | for row in rows: |
| 52 | source = row.get("_source") if isinstance(row, dict) else None |
| 53 | if not isinstance(source, dict) or not source.get("title") or not source.get("url"): |
| 54 | continue |
| 55 | url = str(source["url"]).strip() |
| 56 | text = str(source.get("description") or "").strip() |
| 57 | items.append(jobs._ats_item( |
| 58 | provider=PROVIDER_IBM, |
| 59 | slug="careers.ibm.com", |
| 60 | ident=url.rsplit("=", 1)[-1], |
| 61 | title=str(source["title"]).strip(), |
| 62 | url=url, |
| 63 | description=jobs._clean_html(text), |
| 64 | description_blocks=jobs._block_text(text), |
| 65 | date=None, |
| 66 | department=str(source.get("field_keyword_08") or "").strip(), |
| 67 | location=str(source.get("field_keyword_19") or "").strip(), |
| 68 | company_name="IBM", |
| 69 | whole_posting=True, |
| 70 | )) |
| 71 | return items, total |
| 72 | |
| 73 | |
| 74 | def read_board( |
| 75 | entry: dict[str, Any], *, deadline: float, date_range: tuple[str, str], |
| 76 | ) -> tuple[list[dict[str, Any]], dict[str, Any]]: |
| 77 | """The whole board up to the row ceiling, in the search's own order.""" |
| 78 | |
| 79 | def page(offset: int) -> Callable[[float], Any]: |
| 80 | body = search_body(offset) |
| 81 | return lambda http_deadline: http.post( |
| 82 | SEARCH_URL, body, |
| 83 | headers={"Accept": "application/json"}, |
| 84 | timeout=jobs.API_TIMEOUT_SECONDS, retries=2, deadline_monotonic=http_deadline, |
| 85 | ) |
| 86 | |
| 87 | items, info = jobs._read_newest_first( |
| 88 | page, parse_listing, page_size=PAGE_SIZE, row_ceiling=jobs.COMPANY_BOARD_ROW_CEILING, |
| 89 | window_start=None, deadline=deadline, newest_first=False, |
| 90 | ) |
| 91 | info["board_window_covered"] = False |
| 92 | return items, info |
| 93 |