Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import random
- #Basic PRAW Auth
- ua = '/u/someone for /r/somesub'
- r = praw.Reddit(user_agent=ua)
- #Reddit user which the bot logs into
- user = input('Enter your reddit username ')
- password = input('Enter your reddit password ')
- r.login(user, password)
- #Thread Identification reddit.com/r/subreddit/comments/SUBMISSIONIDHERE/tile_of_thread/
- subid = input('Enter the Submission ID ')
- #Pulls users from thread
- thread = r.get_submission(submission_id=subid)
- thread.replace_more_comments(limit=None, threshold=0)
- flat_list = praw.helpers.flatten_tree(thread.comments)
- authors = []
- #Prints usernames into a csv
- with open('thread.csv', 'w') as f:
- for thing in flat_list:
- #Prevents duplicate usernames from being saved to csv
- if thing.author is not None and thing.author.name not in authors:
- authors.append(thing.author.name)
- f.write(thing.author.name)
- f.write('\n')
- #Reads the thread.csv file and randomly selects a line
- lines = open('thread.csv').read().splitlines()
- #Outputs the random line into a var
- myline = random.choice(lines)
- #Reads the myline var and prints it as a txt file
- with open('winner.txt', 'w') as f:
- f.write(myline)
- f.write('\n')
- #Creates the content of the message to send to the winning user
- input('Now we are going form the message to the winning user')
- subj = input('Enter the subject of the message')
- cont = input('Enter the content of the message')
- input('You may have to enter a captcha')
- #Sends the content to winning user
- r.send_message(myline, subj, cont)
Add Comment
Please, Sign In to add comment