Guest User

Reddit Contest Bot Script

a guest
May 2nd, 2014
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. import praw
  2. import random
  3.  
  4. #Basic PRAW Auth
  5. ua = '/u/someone for /r/somesub'
  6. r = praw.Reddit(user_agent=ua)
  7.  
  8. #Reddit user which the bot logs into
  9. user = input('Enter your reddit username ')
  10. password = input('Enter your reddit password ')
  11.  
  12. r.login(user, password)
  13.  
  14. #Thread Identification reddit.com/r/subreddit/comments/SUBMISSIONIDHERE/tile_of_thread/
  15. subid = input('Enter the Submission ID ')
  16.  
  17. #Pulls users from thread
  18. thread = r.get_submission(submission_id=subid)
  19. thread.replace_more_comments(limit=None, threshold=0)
  20. flat_list = praw.helpers.flatten_tree(thread.comments)
  21.  
  22. authors = []
  23.  
  24. #Prints usernames into a csv
  25. with open('thread.csv', 'w') as f:
  26.     for thing in flat_list:
  27.         #Prevents duplicate usernames from being saved to csv
  28.         if thing.author is not None and thing.author.name not in authors:
  29.             authors.append(thing.author.name)
  30.             f.write(thing.author.name)
  31.             f.write('\n')
  32.  
  33. #Reads the thread.csv file and randomly selects a line
  34. lines = open('thread.csv').read().splitlines()
  35. #Outputs the random line into a var
  36. myline = random.choice(lines)
  37.  
  38. #Reads the myline var and prints it as a txt file
  39. with open('winner.txt', 'w') as f:
  40.     f.write(myline)
  41.     f.write('\n')
  42.  
  43. #Creates the content of the message to send to the winning user
  44. input('Now we are going form the message to the winning user')
  45. subj = input('Enter the subject of the message')
  46. cont = input('Enter the content of the message')
  47. input('You may have to enter a captcha')
  48.  
  49. #Sends the content to winning user
  50. r.send_message(myline, subj, cont)
Add Comment
Please, Sign In to add comment