Skip to content

Instantly share code, notes, and snippets.

@jamesscottbrown
Created January 25, 2016 19:03
Show Gist options
  • Save jamesscottbrown/10ccf359bd96ffe2c80b to your computer and use it in GitHub Desktop.
Save jamesscottbrown/10ccf359bd96ffe2c80b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# James Scott-Brown, 2016-01-25
# This script loops through each of a user's repositories
# for each, it prints the name of each release asset, and how
# many times it has been downloaded
import urllib2
import json
user_name = "sys-bio"
opener = urllib2.build_opener()
def print_repo_stats(full_name):
req = urllib2.Request("https://api.github.com/repos/" + full_name + "/releases")
f = opener.open(req)
rawJSON = f.read()
data = json.loads(rawJSON)
print "\n" + full_name + ":"
for release in data:
assets = release['assets']
for asset in assets:
print asset['name'], asset['download_count']
req = urllib2.Request("https://api.github.com/users/" + user_name + "/repos")
f = opener.open(req)
rawJSON = f.read()
repos = json.loads(rawJSON)
for repo in repos:
print_repo_stats(repo['full_name'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment