Skip to content

Instantly share code, notes, and snippets.

@oliviagallucci
Created September 22, 2023 16:15
Show Gist options
  • Save oliviagallucci/98d6e6963ebbe7b1cbfc116f81d90f27 to your computer and use it in GitHub Desktop.
Save oliviagallucci/98d6e6963ebbe7b1cbfc116f81d90f27 to your computer and use it in GitHub Desktop.
Use `pip install requests` before running.
import requests
# replace 'YOUR_GITHUB_USERNAME' with your GitHub username
github_username = 'YOUR_GITHUB_USERNAME'
# github API endpoint to retrieve user information
api_url = f'https://api.github.com/users/{github_username}'
try:
# send a GET request to the GitHub API
response = requests.get(api_url)
# check if the request was successful (status code 200)
if response.status_code == 200:
# parse the JSON response
user_data = response.json()
# print some user information
print(f"github username: {user_data['login']}")
print(f"name: {user_data['name']}")
print(f"bio: {user_data['bio']}")
print(f"followers: {user_data['followers']}")
print(f"following: {user_data['following']}")
print(f"public repositories: {user_data['public_repos']}")
else:
# print an error message if the request was not successful
print(f"request failed with status code {response.status_code}")
except requests.exceptions.RequestException as e:
# handle any exceptions that may occur during the request
print(f"an error occurred: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment