#Script to make a graph of your reddit comment and submission karma over the last 30 days

#Requires Python 2.6 and GNUPlot

#My apologies for the complete messiness of this code. I wrote it in like an hour

#Feel free to clean up or appropriate:

#This code is CC-By (that means use it however the hell you want, but please give me credit).

#Please let me know if you do anything cool with it

# This code is by Ilyanep (http://reddit.com/user/ilyanep)

#The Following describes three files, update.py, RedditKarma.p, and karma

#To make this work just run the latter

########update.py#########

import urllib , re , fileinput , os , datetime

#Open userpage and grab karma and comment karma (please never change your page layout, reddit)

page = urllib . urlopen ( "http://www.reddit.com/user/ilyanep" )

pagetext = page. read ( )

matched = re . search ( "karma: <b>([0-9]+)<" , pagetext )

currentkarma = matched. groups ( 1 ) [ 0 ]

matched2 = re . search ( "comment karma: <b>([0-9]+)<" , pagetext )

currentcommentkarma = matched2. groups ( 1 ) [ 0 ]

#Open old file containing karma and grab old data, append number of days, create new file

f = open ( "karma" , 'r' )

newlines = [ "#Days ago Comment Karma Submission Karma

" ]

tab = 4 * " "

for line in f:

matched3 = re . search ( " \# ?([0-9]+) \s +([0-9]+) \s +([0-9]+) \s + \# ?(.+)" , line )

if matched3 is None :

continue

if int ( matched3. group ( 1 ) ) == 30 :

newlines. append ( "#" + str ( int ( matched3. group ( 1 ) ) + 1 ) + tab + matched3. group ( 2 ) + tab + matched3. group ( 3 ) +tab+ matched3. group ( 4 ) + "

" )

continue

newlines. append ( str ( int ( matched3. group ( 1 ) ) + 1 ) +tab+matched3. group ( 2 ) +tab+matched3. group ( 3 ) +tab+ "#" +matched3. group ( 4 ) + "

" )

newlines. append ( "0" +tab+currentcommentkarma+tab+currentkarma+tab+ "#" + datetime . datetime . today ( ) . ctime ( ) + "

" )

mu = open ( "karmaNew" , 'w' )

mu. writelines ( newlines )

mu. close ( )

f. close ( )

#Gah extremely insecure code following:

#Dance around and replace the karma data file

os . system ( "mv karma karmaOld" )

os . system ( "mv karmaNew karma" )

os . system ( "rm karmaOld" )

#Create the plot

os . system ( "gnuplot RedditKarma.p" )

##############RedditKarma.p###############

set xlabel "Days Ago"

set ylabel "Karma"

set xrange [ 30 : 0 ]

set terminal png

set output "karmaGraph.png"

set title "Ilyanep Karma on reddit"

plot "karma" using 1 : 2 title 'Comment' with linespoints , \

"karma" using 1 : 3 title 'Submission' with linespoints

###############karma#######################

#Days ago Comment Karma Submission Karma