Created
March 1, 2010 16:43
-
-
Save philikon/318535 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
""" | |
Takes CSV locale statistics from addons.mozilla.org and sums numbers | |
for same languages (e.g. es = es + es_ES + es_MX + ...). Output is | |
similarly formatted CSV. | |
""" | |
import sys | |
languages = {} | |
for line in open(sys.argv[-1]): | |
if line.startswith('# Fields'): | |
line = line[11:-2] | |
locales = line.split(';')[2:] | |
for i, locale in enumerate(locales): | |
chunks = locale.split('-') | |
languages.setdefault(chunks[0], []).append(i) | |
print 'date,total,' + ','.join(sorted(languages)) | |
continue | |
if line.startswith('#'): | |
continue | |
data = line.split(','); | |
date, total = data.pop(0), data.pop(0) | |
data = [int(value) for value in data] | |
print ( | |
date + ',' + total + ',' + | |
','.join(str(sum(data[i] for i in positions)) | |
for lang, positions in sorted(languages.items())) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment