Skip to content

Instantly share code, notes, and snippets.

@dstufft
Created February 26, 2012 20:12
Show Gist options
  • Save dstufft/1918771 to your computer and use it in GitHub Desktop.
Save dstufft/1918771 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import urllib2
import bz2
import csv
from StringIO import StringIO
package_name, year_month = sys.argv[1:3]
f = urllib2.urlopen("http://pypi.python.org/stats/months/" + year_month + ".bz2")
data = StringIO(bz2.decompress(f.read()))
counts = {}
for line in csv.reader(data):
package, filename, ua, count = line
if package.lower() == package_name.lower():
if "py2.3" in filename:
counts["python2.3"] = counts.get("python2.3", 0) + int(count)
elif "py2.4" in filename:
counts["python2.4"] = counts.get("python2.4", 0) + int(count)
elif "py2.5" in filename:
counts["python2.5"] = counts.get("python2.5", 0) + int(count)
elif "py2.6" in filename:
counts["python2.6"] = counts.get("python2.6", 0) + int(count)
elif "py2.7" in filename:
counts["python2.7"] = counts.get("python2.7", 0) + int(count)
elif "py3.0" in filename:
counts["python3.0"] = counts.get("python3.0", 0) + int(count)
elif "py3.1" in filename:
counts["python3.1"] = counts.get("python3.1", 0) + int(count)
elif "py3.2" in filename:
counts["python3.2"] = counts.get("python3.2", 0) + int(count)
else:
counts["unknown"] = counts.get("unknown", 0) + int(count)
print counts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment