#!/usr/bin/env python
# needs dev-python/matplotlib
# Copyright Mike Doty <kingtaco@gentoo.org> GPL-2

from pylab import *
from pprint import *
import datetime
from pytz import timezone

dates=[]
topics=[]
posts=[]

def parse_file(name):
    global dates,topics,posts
    f=file(name,"r")
    for line in f:
        try:
            (date,topic,post) = line.split(',',2)
        except:
            pass
        (y,m,d)=date.split('-',2)
        topics.append(int(topic))
        posts.append(int(post))
        dates.append(datetime.date(int(y),int(m),int(d)))
        
    
if __name__ == "__main__":
    parse_file(sys.argv[1])
    plot_date(date2num(dates),topics,fmt='r-',tz=timezone('UTC'))
    plot_date(date2num(dates),posts,'b-',tz=timezone('UTC'))
    months=MonthLocator()
    fmt=DateFormatter('%b %y')
    ax=gca()
    ax.xaxis.set_major_locator(months)
    ax.xaxis.set_major_formatter(fmt)
    legend(('topics', 'posts'))
    show()
    
