| 14 | |
| 15 | |
| 16 | def get(entity: str, query: dict = None) -> dict: |
| 17 | if query is None: |
| 18 | query = {} |
| 19 | path = entity |
| 20 | if query: |
| 21 | querystring = urllib.parse.urlencode(query) |
| 22 | path += f"?{querystring}" |
| 23 | print(f"Getting {path}") |
| 24 | req = urllib.request.Request( |
| 25 | f"https://api.github.com/{path}", |
| 26 | None, |
| 27 | { |
| 28 | "User-Agent": USER_AGENT, |
| 29 | "Authorization": f"token {ACCESS_TOKEN}", |
| 30 | "Accept": "application/vnd.github.v3+json", |
| 31 | }, |
| 32 | ) |
| 33 | result = urllib.request.urlopen(req) |
| 34 | # It's ok not to check for error codes here. We'll throw either way |
| 35 | return json.loads(result.read()) |
| 36 | |
| 37 | |
| 38 | def paginated_get(entity: str, query: dict = None) -> [dict]: |