Skip to content

Instantly share code, notes, and snippets.

@po5i
Created July 1, 2022 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save po5i/3bf82c85b8f7e3dbf892f4107ce66c23 to your computer and use it in GitHub Desktop.
Save po5i/3bf82c85b8f7e3dbf892f4107ce66c23 to your computer and use it in GitHub Desktop.
Print a list of repositories - Supports async
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