Uptonian Thoughts

Twitter Stats

· ·

Update: TweetStats webifies a version of these Twitter statistics.

Twitter stats, by hour.

Damon Cortesi wrote a pretty nifty script to grab some Twitter statistics. A bunch of people modified his script in order to webify it, plot the results using gnuplot, and plot the results with the Google Charts API.

This last modification really intrigued me, as I know there are a few wrappers for the Google Charts API available, including one for Python. I decided to modify Colin Barrett’s Python script that uses the Google Charts API to use the pygooglechart module.

So now instead of:

if f[0] == "\n":
    s = "http://chart.apis.google.com/chart?cht=bvg&chbh;=15&chs;=600x300&chd;=t:%s&chxt;=y,x&
    chxr=0,0,%d&chtt;=%s"
    s = s % ( str(map(lambda x: x*100/max(v), v)).replace(" ", "")[1:-1], max(v), t )

we have:

# If we are at a newline, we have just finished gathering data for a single chart
if fields[0] == "\n":
    # Most of the time we are generating a vertical bar chart
    chart = GroupedVerticalBarChart(600, 300)
    # Set the y-axis range according to the current data
    chart.set_axis_range(Axis.LEFT, 0, max(chartData))

I also commented my modifications because I’m still on winter break and I felt like it.

You can download my modified script here. Make sure you have the pygooglechart module and read the included README.txt file.