Skip to content

Instantly share code, notes, and snippets.

@Hanse00
Created March 20, 2014 22:07
Show Gist options
  • Save Hanse00/9674972 to your computer and use it in GitHub Desktop.
Save Hanse00/9674972 to your computer and use it in GitHub Desktop.
Quick python script to list the number of downloads per release in a repository.
import urllib2
#GitHub's API url
github_url = "https://api.github.com/"
#Release URL
github_release = "repos/<user>/<repo>/releases"
#Request info about releases from GitHub
response = urllib2.urlopen(github_url + github_release)
#Full response
response_text = response.read()
#Formatting of response (newline after commans)
formatted_string = ""
for char in response_text:
if char == ",":
new_char = ",\n"
else:
new_char = char
formatted_string += new_char
#Iterate through every tag
search_point = 0
while formatted_string.find("tag_name", search_point) != -1:
#Find where in the string the tag and download texts are
find_point = formatted_string.find("tag_name", search_point)
download_point = formatted_string.find("download_count", find_point)
#Grab download count based on tag location
download_count = formatted_string[download_point + 16:formatted_string.find(",", download_point + 1)]
#Grab version name based on tag
version_name = formatted_string[find_point + 11:formatted_string.find(",", find_point + 1) - 1]
#Print version and downloads
print version_name + "\t" + download_count
#Search on!
search_point = find_point + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment