MCPcopy
hub / github.com/bobeff/open-source-games / fetch_user

Function fetch_user

scripts/coauthor.py:11–29  ·  view source on GitHub ↗
(username: str)

Source from the content-addressed store, hash-verified

9API = "https://api.github.com/users/{}"
10
11def fetch_user(username: str) -> dict:
12 headers = {
13 "Accept": "application/vnd.github+json",
14 "User-Agent": "coauthor-line-script",
15 }
16 token = os.getenv("GITHUB_TOKEN") or os.getenv("GH_TOKEN")
17 if token:
18 headers["Authorization"] = f"Bearer {token}"
19
20 req = urllib.request.Request(API.format(username), headers=headers)
21 try:
22 with urllib.request.urlopen(req) as resp:
23 return json.load(resp)
24 except urllib.error.HTTPError as e:
25 msg = e.read().decode("utf-8", "replace")
26 print(f"error: GitHub API returned {e.code} {e.reason} for '{username}'", file=sys.stderr)
27 if msg.strip():
28 print(msg, file=sys.stderr)
29 raise SystemExit(2)
30
31def main(argv: list[str]) -> int:
32 if len(argv) != 2 or argv[1] in ("-h", "--help"):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected