Skip to content

Instantly share code, notes, and snippets.

@chrisb13
Created April 16, 2025 03:29
Show Gist options
  • Save chrisb13/9a5f4d8a2cb911b879f0dce206d44dc3 to your computer and use it in GitHub Desktop.
Save chrisb13/9a5f4d8a2cb911b879f0dce206d44dc3 to your computer and use it in GitHub Desktop.
quick script to download csv file of all github repos associated with an organisation
import requests
import csv
# GitHub API URL for the COSIMA organization repositories
url = "https://api.github.com/orgs/cosima/repos"
# Function to fetch all repositories with pagination
def fetch_all_repos(url):
repos = []
while url:
response = requests.get(url)
response_data = response.json()
repos.extend(response_data)
# Check if there is a next page
if 'next' in response.links:
url = response.links['next']['url']
else:
url = None
return repos
# Fetch all repositories
repos = fetch_all_repos(url)
# Open CSV file for writing
with open('cosima.csv', 'w', newline='') as csvfile:
fieldnames = ['name', 'html_url', 'description', 'language', 'created_at', 'updated_at', 'fork']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
# Write the header
writer.writeheader()
# Write the repository data
for repo in repos:
writer.writerow({
'name': repo['name'],
'html_url': repo['html_url'],
'description': repo['description'],
'language': repo['language'],
'created_at': repo['created_at'],
'updated_at': repo['updated_at'],
'fork': repo['fork']
})
print("All repositories have been saved to cosima.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment