Advertisement
Guest User

A858 Archive Bot in Python, thesoundofbutthurt 11/5/2012.

a guest
Nov 5th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. import praw
  2.  
  3. def write_plain(file_name, selftext):
  4.     f = open(file_name+'_plain.txt', 'w')
  5.     f.write(selftext + "\n")
  6.     f.close()
  7.  
  8. def write_fancy_old(file_name, data):
  9.     f = open(file_name+'_fancy.txt', 'w')
  10.     for i in data:
  11.         f.write(str(i) + "\n")
  12.  
  13. def write_fancy(title, data):
  14.     f = open(title+'.xml', 'w')
  15.     f.write("<data title=" + title)
  16.     for i in data:
  17.         f.write("<item>\n")
  18.         f.write("\t" + str(i) + "\n")
  19.         f.write("</item>\n")
  20.         f.write("</data>")
  21.  
  22. username = 'A858_archive'   # Or whatever
  23. password = 'PASSWORD_HERE'
  24.  
  25. bot = praw.Reddit(user_agent='USER_AGENT')
  26. print "Starting A858 Archive Bot"
  27. print "Logging in..."
  28. bot.login(username, password)
  29. print "Logged in."
  30. subreddit = bot.get_subreddit('A858DE45F56D9BC9')
  31. print "Checking previous entries..."
  32. done = open('done.txt', 'r+')
  33. old = done.read().split()
  34. done.close()
  35. count = 0
  36. print "Starting, looking for new A858DE45F56D9BC9 posts..."
  37. for sub in subreddit.get_hot(limit=10):
  38.     done = open('done.txt', 'a')
  39.     if sub.id not in old:
  40.         done.write(sub.id + " ")
  41.         count += 1
  42.         title = sub.title
  43.         print "Post number: %d with title: %s" % (count, title)
  44.         sub.save()
  45.         sub.upvote()
  46.         write_plain(title, sub.selftext)
  47.         write_fancy(title, [title, sub.created_utc, sub.short_link, sub.selftext])
  48.     done.close()
  49. print count, " new posts since last run."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement