-
-
Save willingc/9c5572a6fb706f3e65b6262d56abd886 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
""" | |
Script to get watchers/stars/forks for all repos on a github organization | |
Set GITHUB_API_TOKEN environment variable if you are hitting the API rate limit | |
Requires pygithub and Python 3.6: | |
pip install pygithub | |
Usage: | |
python org-activity.py <org-name> | |
e.g. | |
python org-activity.py binder-examples | |
LICENSE: CC-0 or Public Domain | |
""" | |
import os | |
import sys | |
# pip install pygithub | |
from github import Github as GitHub # fix case! | |
def main(org_name): | |
gh = GitHub() | |
if 'GITHUB_API_TOKEN' in os.environ: | |
gh = GitHub(os.environ['GITHUB_API_TOKEN']) | |
else: | |
gh = GitHub() | |
org = gh.get_organization(org_name) | |
totals = { | |
'watchers': 0, | |
'stars': 0, | |
'forks': 0, | |
} | |
print(f"{'repo':40} {'watch'} {'stars'} {'forks'}") | |
for repo in org.get_repos(): | |
print(f"{repo.full_name:40}" | |
f" {repo.watchers_count:5}" | |
f" {repo.stargazers_count:5}" | |
f" {repo.forks_count:5}" | |
) | |
totals['watchers'] += repo.watchers_count | |
totals['stars'] += repo.stargazers_count | |
totals['forks'] += repo.forks_count | |
print("\nTotals:") | |
for key, value in totals.items(): | |
print(f"{key:8}: {value:4}") | |
if __name__ == '__main__': | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment