|
27 | 27 | SchoolSearchResult, |
28 | 28 | ) |
29 | 29 | from .queries import ( |
30 | | - GET_SCHOOL_QUERY, |
31 | | - GET_TEACHER_QUERY, |
32 | 30 | RATINGS_LIST_QUERY, |
33 | 31 | SCHOOL_RATINGS_LIST_QUERY, |
34 | 32 | SCHOOL_SEARCH_RESULTS_QUERY, |
@@ -285,20 +283,13 @@ def iter_professors_for_school( |
285 | 283 | # ---- Professor details + ratings --------------------------------------------- |
286 | 284 |
|
287 | 285 | def get_professor(self, professor_id: str) -> Professor: |
288 | | - """Fetch a single professor by legacy numeric ID (GetTeacherQuery).""" |
289 | | - node_id = _teacher_node_id(professor_id) |
290 | | - data = self.raw_query({ |
291 | | - "operationName": "GetTeacherQuery", |
292 | | - "query": GET_TEACHER_QUERY, |
293 | | - "variables": {"id": node_id}, |
294 | | - }) |
| 286 | + """Fetch a single professor by legacy numeric ID. |
295 | 287 |
|
296 | | - node = (data.get("data") or {}).get("node") |
297 | | - if not node: |
298 | | - raise ParsingError( |
299 | | - f"Teacher not found in GraphQL response for id={professor_id}" |
300 | | - ) |
301 | | - return self._parse_professor_node(node) |
| 288 | + Uses the ratings list query with a minimal page size to retrieve |
| 289 | + full teacher details in a single request. |
| 290 | + """ |
| 291 | + page = self._fetch_professor_ratings_page(professor_id, first=1) |
| 292 | + return page.professor |
302 | 293 |
|
303 | 294 | def get_professor_ratings_page( |
304 | 295 | self, |
@@ -399,20 +390,13 @@ def iter_professor_ratings( |
399 | 390 | # ---- School details + ratings ------------------------------------------------ |
400 | 391 |
|
401 | 392 | def get_school(self, school_id: str) -> School: |
402 | | - """Fetch a single school by legacy numeric ID (GetSchoolQuery).""" |
403 | | - node_id = _school_node_id(school_id) |
404 | | - data = self.raw_query({ |
405 | | - "operationName": "GetSchoolQuery", |
406 | | - "query": GET_SCHOOL_QUERY, |
407 | | - "variables": {"id": node_id}, |
408 | | - }) |
| 393 | + """Fetch a single school by legacy numeric ID. |
409 | 394 |
|
410 | | - node = (data.get("data") or {}).get("node") |
411 | | - if not node: |
412 | | - raise ParsingError( |
413 | | - f"School not found in GraphQL response for id={school_id}" |
414 | | - ) |
415 | | - return self._parse_school_node(node) |
| 395 | + Uses the school ratings list query with a minimal page size to retrieve |
| 396 | + full school details (including category summaries) in a single request. |
| 397 | + """ |
| 398 | + page = self._fetch_school_ratings_page(school_id, first=1) |
| 399 | + return page.school |
416 | 400 |
|
417 | 401 | def get_compare_schools( |
418 | 402 | self, school_id_1: str, school_id_2: str |
@@ -596,13 +580,7 @@ def _fetch_school_ratings_page( |
596 | 580 | "GraphQL response missing data.node (school not found or invalid id)" |
597 | 581 | ) |
598 | 582 |
|
599 | | - school = self._parse_school_node({ |
600 | | - "id": node.get("legacyId") or node.get("id") or school_id, |
601 | | - "name": node.get("name"), |
602 | | - "city": node.get("city"), |
603 | | - "state": node.get("state"), |
604 | | - "country": node.get("country"), |
605 | | - }) |
| 583 | + school = self._parse_school_node(node) |
606 | 584 |
|
607 | 585 | ratings_conn = node.get("ratings") or {} |
608 | 586 | edges = ratings_conn.get("edges") or [] |
|
0 commit comments