MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / _build_scholar_profile_url

Function _build_scholar_profile_url

agents/coldstart-agent/main.py:608–640  ·  view source on GitHub ↗

Normalize a Scholar profile URL and request a larger publication page size.

(
    scholar_url: str,
    *,
    cstart: int = 0,
    pagesize: Optional[int] = None,
    hl: str = "en",
)

Source from the content-addressed store, hash-verified

606
607
608def _build_scholar_profile_url(
609 scholar_url: str,
610 *,
611 cstart: int = 0,
612 pagesize: Optional[int] = None,
613 hl: str = "en",
614) -> str:
615 """Normalize a Scholar profile URL and request a larger publication page size."""
616 candidate = _collapse_whitespace(scholar_url)
617 if not candidate:
618 raise ValueError("empty scholar url")
619 if "://" not in candidate:
620 candidate = f"https://{candidate.lstrip('/')}"
621
622 parsed = urlsplit(candidate)
623 if not parsed.netloc:
624 raise ValueError("invalid scholar url")
625
626 query = dict(parse_qsl(parsed.query, keep_blank_values=True))
627 query["hl"] = hl or query.get("hl") or "en"
628 query["cstart"] = str(max(0, int(cstart)))
629 resolved_page_size = pagesize or _get_env_int("PAPERFLOW_SCHOLAR_PAGE_SIZE", 100)
630 query["pagesize"] = str(max(20, int(resolved_page_size)))
631
632 return urlunsplit(
633 (
634 parsed.scheme or "https",
635 parsed.netloc,
636 parsed.path or "/citations",
637 urlencode(query),
638 parsed.fragment,
639 )
640 )
641
642
643def _parse_scholar_stats(html_text: str) -> Dict[str, int]:

Callers 1

Calls 3

_collapse_whitespaceFunction · 0.85
getMethod · 0.80
_get_env_intFunction · 0.70

Tested by

no test coverage detected