Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.01 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os
  4. import praw
  5. import time
  6. import pickle
  7. import random
  8. import string
  9. from config import *
  10.  
  11. r = praw.Reddit(user_agent = USER_AGENT)
  12. r.login(USERNAME, PASSWORD)
  13.  
  14. subreddit = r.get_subreddit(SUBREDDIT)
  15. submissions = list(subreddit.get_new())
  16.  
  17. try:
  18.  
  19.     with open('done', 'r') as f:
  20.         done = pickle.load(f)
  21.  
  22.     while len(done) > 50:
  23.         del(done[0])
  24.  
  25. except:
  26.  
  27.     done = []
  28.     for submission in submissions:
  29.         done.append(submission.id)
  30.     for i in list(r.get_inbox()):
  31.         if i.id not in done:
  32.             done.append(i.id)
  33.  
  34.     with open('done', 'w') as f:
  35.         pickle.dump(done, f)
  36.  
  37. def Word(Title, inGroup):
  38.  
  39.     alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  40.                 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ']
  41.     array = []
  42.     for i in Title.lower():
  43.         if i in [j.lower() for j in alphabet]:
  44.             array.append(i)
  45.  
  46.     cleanedString = ''.join(array)
  47.     titleAsList = cleanedString.split(' ')
  48.     inGroup = [i.lower() for i in inGroup]
  49.  
  50.     for i in titleAsList:
  51.         if i.lower() in inGroup:
  52.             return True
  53.  
  54. def main():
  55.  
  56.     submissions = list(subreddit.get_new())
  57.  
  58.     for submission in submissions:
  59.  
  60.         try:
  61.             if submission.id not in done:
  62.                 done.append(submission.id)
  63.                 with open('done', 'w') as f:
  64.                     pickle.dump(done, f)
  65.  
  66.                 if submission.is_self == True: #Set to False before going Live
  67.                     if Word(submission.title, RIPkitty) == True:
  68.                         break
  69.                     elif Word(submission.title, Fritz) == True:
  70.                         submission.add_comment(random.choice(FritzReply))
  71.                     elif Word(submission.title, Kuro) == True:
  72.                         submission.add_comment(random.choice(KuroReply))
  73.                     elif Word(submission.title, Spam) == True:
  74.                         submission.add_comment(random.choice(SpamReply))
  75.                     elif Word(submission.title, Felix) == True:
  76.                         submission.add_comment(random.choice(FelixReply))
  77.                     elif Word(submission.title, Xander) == True:
  78.                         submission.add_comment(random.choice(XanderReply))
  79.                     elif Word(submission.title, XX) == True:
  80.                         submission.add_comment(random.choice(XXReply))
  81.                     elif Word(submission.title, XY) == True:
  82.                         submission.add_comment(random.choice(XYReply))
  83.                     else:
  84.                         submission.add_comment(random.choice(default_replies))
  85.  
  86.         except Exception as e:
  87.  
  88.             log = "Sub Error: "+str(e)+" on "+submission.title+" "+submission.id+" @ "+str(time.time())+"\n"
  89.             with open("errorlog.txt", "a") as f:
  90.                 f.writelines(log)
  91.  
  92.     for i in list(r.get_inbox()):
  93.  
  94.         try:
  95.             if i.id not in done:
  96.                 done.append(i.id)
  97.                 with open('done', 'w') as f:
  98.                     pickle.dump(done, f)
  99.  
  100.                 if i.was_comment == True:
  101.                     subj = i.permalink
  102.                     msg = i.body
  103.                     r.send_message(bot_op, subj, msg)
  104.  
  105.                 if i.subject.split(" ")[0] == "re:":
  106.                     comment = r.get_submission(i.subject.split(" ")[1]).comments[0]
  107.                     comment.reply(i.body)
  108.  
  109.         except Exception as e:
  110.  
  111.             log = "Sub Error (PM): "+str(e)+" on "+i.body+" "+i.id+" @ "+str(time.time())+"\n"
  112.             with open("errorlog.txt", "a") as f:
  113.                 f.writelines(log)
  114.  
  115.  
  116. if __name__ == "__main__":
  117.  
  118.     while True:
  119.         try:
  120.             main()
  121.  
  122.         except Exception as e:
  123.             log = "General Error: "+str(e)+" @ "+str(time.time())+"\n"
  124.             with open('errorlog.txt', 'a') as f:
  125.                 f.writelines(log)
  126.  
  127.         print "Sleeping for 2 minutes."
  128.         time.sleep(120)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement