Created
January 6, 2024 06:35
-
-
Save sunnydsouza/6acc03b8f6792cda773084353bb09de8 to your computer and use it in GitHub Desktop.
This file contains 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 pandas as pd | |
GITHUB_USERNAME = 'your-username' | |
GITHUB_TOKEN = 'your-github-token' | |
def fetch_repos(url, headers): | |
response = requests.get(url, headers=headers) | |
if response.status_code != 200: | |
raise Exception(f"GitHub API Error: {response.status_code} {response.json()}") | |
search_results = response.json() | |
repos = search_results['items'] | |
# Check if pagination 'next' link is present | |
if 'next' in response.links.keys(): | |
repos.extend(fetch_repos(response.links['next']['url'], headers)) | |
return repos | |
headers = {'Authorization': f'token {GITHUB_TOKEN}'} | |
search_url = f"https://api.github.com/search/repositories?q=user:{GITHUB_USERNAME}&per_page=100" # Adjust per_page as needed | |
repos = fetch_repos(search_url, headers) | |
repo_list = [] | |
for repo in repos: | |
repo_list.append({ | |
'Name': repo['name'], | |
'URL': repo['html_url'], | |
'Private': repo['private'], | |
'Description': repo.get('description', 'No description'), | |
'Language': repo.get('language', 'Not specified') | |
}) | |
df = pd.DataFrame(repo_list) | |
df.to_excel('github_repos.xlsx', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment