Created
February 26, 2012 20:12
-
-
Save dstufft/1918771 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
#!/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