Skip to content

Instantly share code, notes, and snippets.

@xrotwang
Created January 30, 2015 07:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xrotwang/2388acba500fae432466 to your computer and use it in GitHub Desktop.
Save xrotwang/2388acba500fae432466 to your computer and use it in GitHub Desktop.
List an organizations GitHub repositories and their size
import sys
import re
import requests
from hurry.filesize import size
NEXT = re.compile('\<(?P<url>[^\>]+)\>; rel\=\"next\"')
def get_repos(org):
repos = []
m = NEXT.search('<https://api.github.com/orgs/%s/repos>; rel="next"' % org)
while m:
res = requests.get(m.group('url'))
repos.extend(res.json())
m = NEXT.search(res.headers.get('link', ''))
return repos
if __name__ == '__main__':
repos = get_repos(sys.argv[1])
max_name = max([len(r['name']) for r in repos])
for repos in sorted(get_repos(sys.argv[1]), key=lambda r: r['size'], reverse=True):
print repos['name'].ljust(max_name + 1), size(repos['size'] * 1024)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment