Guest User

Ilyanep

a guest
Aug 18th, 2009
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. #Script to make a graph of your reddit comment and submission karma over the last 30 days
  2. #Requires Python 2.6 and GNUPlot
  3. #My apologies for the complete messiness of this code. I wrote it in like an hour
  4. #Feel free to clean up or appropriate:
  5. #This code is CC-By (that means use it however the hell you want, but please give me credit).
  6. #Please let me know if you do anything cool with it
  7. # This code is by Ilyanep (http://reddit.com/user/ilyanep)
  8.  
  9. #The Following describes three files, update.py, RedditKarma.p, and karma
  10. #To make this work just run the latter
  11.  
  12. ########update.py#########
  13. import urllib,re,fileinput,os,datetime
  14.  
  15. #Open userpage and grab karma and comment karma (please never change your page layout, reddit)
  16. page = urllib.urlopen("http://www.reddit.com/user/ilyanep")
  17. pagetext = page.read()
  18. matched = re.search("karma: &#32;<b>([0-9]+)<", pagetext)
  19. currentkarma = matched.groups(1)[0]
  20. matched2 = re.search("comment karma: &#32;<b>([0-9]+)<", pagetext)
  21. currentcommentkarma = matched2.groups(1)[0]
  22.  
  23. #Open old file containing karma and grab old data, append number of days, create new file
  24. f = open("karma", 'r')
  25. newlines = ["#Days ago    Comment Karma    Submission Karma\n"]
  26. tab = 4*" "
  27. for line in f:
  28.     matched3 = re.search("\#?([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+\#?(.+)", line)
  29.     if matched3 is None:
  30.         continue
  31.     if int(matched3.group(1)) == 30:
  32.         newlines.append("#" + str(int(matched3.group(1))+1) + tab + matched3.group(2) + tab + matched3.group(3)+tab+ matched3.group(4)+"\n")
  33.         continue
  34.     newlines.append(str(int(matched3.group(1))+1) +tab+matched3.group(2)+tab+matched3.group(3)+tab+"#"+matched3.group(4)+"\n")
  35.  
  36. newlines.append("0"+tab+currentcommentkarma+tab+currentkarma+tab+"#"+datetime.datetime.today().ctime()+"\n")
  37. mu = open("karmaNew", 'w')
  38. mu.writelines(newlines)
  39. mu.close()
  40. f.close()
  41.  
  42. #Gah extremely insecure code following:
  43. #Dance around and replace the karma data file
  44. os.system("mv karma karmaOld")
  45. os.system("mv karmaNew karma")
  46. os.system("rm karmaOld")
  47.  
  48. #Create the plot
  49. os.system("gnuplot RedditKarma.p")
  50.  
  51. ##############RedditKarma.p###############
  52. set xlabel "Days Ago"
  53. set ylabel "Karma"
  54. set xrange [30:0]
  55. set terminal png
  56. set output "karmaGraph.png"
  57. set title "Ilyanep Karma on reddit"
  58. plot "karma" using 1:2 title 'Comment' with linespoints, \
  59.      "karma" using 1:3 title 'Submission' with linespoints
  60.  
  61. ###############karma#######################
  62. #Days ago    Comment Karma    Submission Karma
  63. 0    5089    632    #Tue Aug 18 15:11:42 2009
  64.  
Add Comment
Please, Sign In to add comment