Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
phpbb-parse-statistics
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
if len(sys.argv) != 2:
print 'Usage:',sys.argv[0],'file_with_statistics'
sys.exit()
stats = {}
months = {'Jan':'01','Feb':'02','Mar':'03','Apr':'04','May':'05','Jun':'06','Jul':'07','Aug':'08','Sep':'09','Oct':'10','Nov':'11','Dec':'12'}
with open(sys.argv[1]) as f:
posts = f.readlines()
posts = [x.strip() for x in posts]
for post in posts:
month = post.split(' ')[1]
year = post.split(' ')[3]
month = months.get(month,'00')
key = year + '-' + month
if not stats.has_key(key):
stats[key] = 0
stats[key] += 1
for key in sorted(stats.iterkeys()):
print "%s\t%s" % (key,stats[key])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment