Last active
March 13, 2020 13:47
-
-
Save MrCordeiro/9a942a655b3e0aa4c2ef83e0b6c21062 to your computer and use it in GitHub Desktop.
Lists public repos from an user
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 csv | |
import requests | |
def list_github_repos(user_name): | |
""" | |
Lists public repositories for the specified user. | |
Args: | |
user_name (str): user whose repos you want listed | |
""" | |
# change these things for your org | |
pages_to_fetch = 2 # number of repos you have, divided by 100. kinda hack-y! | |
api_url = f"https://api.github.com/users/{user_name}/repos?per_page=100" | |
repos_list = [] | |
fields = [ | |
'name', | |
'html_url', | |
'stargazers_count', | |
'forks', | |
'description', | |
'homepage', | |
'language', | |
'created_at', | |
'updated_at', | |
] | |
for page in range(1, (pages_to_fetch + 1)): | |
print("Page %s" % page) | |
repos = requests.get(api_url + "&page=" + str(page)) | |
if repos.status_code is 200: | |
for r in repos.json(): | |
repos_list.append([r[key] for key in fields]) | |
print("Repo list created. Length: %s" % len(repos_list)) | |
outp = open(('%s_repos.csv' % org_name), 'w') | |
writer = csv.writer(outp) | |
writer.writerow(fields) # header | |
writer.writerows(repos_list) # data | |
outp.close() | |
print("File written: %s" % ("{user_name}_repos.csv")) | |
print("done") | |
if __name__ == "__main__": | |
list_github_repos() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment