GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Python/web_programming/fetch_github_info.py at master · D4VA/Python Expand file tree/ Copy pathfetch_github_info.pyMore file actions 50 lines (38 loc) · 1.42 KB / Copy pathfetch_github_info.pyFile metadata and controls50 lines (38 loc) · 1.42 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #!/usr/bin/env python3 """ Created by sarathkaul on 14/11/19 Updated by lawric1 on 24/11/20 Authentication will be made via access token. To generate your personal access token visit https://github.com/settings/tokens. NOTE: Never hardcode any credential information in the code. Always use an environment file to store the private information and use the `os` module to get the information during runtime. Create a ".env" file in the root directory and write these two lines in that file with your token:: #!/usr/bin/env bash export USER_TOKEN="" """ import os from typing import Any, Dict import requests BASE_URL = "https://api.github.com" # https://docs.github.com/en/free-pro-team@latest/rest/reference/users#get-the-authenticated-user AUTHENTICATED_USER_ENDPOINT = BASE_URL + "/user" # https://github.com/settings/tokens USER_TOKEN = os.environ.get("USER_TOKEN", "") def fetch_github_info(auth_token: str) -> Dict[Any, Any]: """ Fetch GitHub info of a user using the requests module """ headers = { "Authorization": f"token {auth_token}", "Accept": "application/vnd.github.v3+json", } return requests.get(AUTHENTICATED_USER_ENDPOINT, headers=headers).json() if __name__ == "__main__": # pragma: no cover if USER_TOKEN: for key, value in fetch_github_info(USER_TOKEN).items(): print(f"{key}: {value}") else: raise ValueError("'USER_TOKEN' field cannot be empty.") |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |