Created
July 1, 2022 18:44
-
-
Save po5i/3bf82c85b8f7e3dbf892f4107ce66c23 to your computer and use it in GitHub Desktop.
Print a list of repositories - Supports async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import aiohttp | |
BASE_URL = "https://api.github.com/users/{}/repos" | |
def get_repos(username: str) -> None: | |
response = requests.get(BASE_URL.format(username)) | |
try: | |
print(f"Repositories from {username}:") | |
print([repo["name"] for repo in response.json()]) | |
except Exception as e: | |
print(f"Error: {e}") | |
async def get_repos_async(username: str) -> None: | |
async with aiohttp.ClientSession( | |
connector=aiohttp.TCPConnector(verify_ssl=False) | |
) as session: | |
try: | |
async with session.get(BASE_URL.format(username)) as response: | |
response = await response.json() | |
print([repo["name"] for repo in response]) | |
except Exception as e: | |
print(f"Error: {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment