Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import re
- import time
- import datetime
- def get_time():
- return time.mktime(datetime.datetime.now().timetuple())
- def login(password):
- reddit = praw.Reddit(
- username='MyRSSBot',
- password=password,
- client_id='qTnjdOyhvYjzWw',
- client_secret='t7pZnB4QboZ9r1x09-QEUO5NHdI',
- user_agent='NeutralContentAdder v2 - adding neutral politics to the sub.')
- return reddit
- def write_to_file(username, file='users.txt'):
- with open(file,'a') as f:
- f.write(username+'\n')
- f.close()
- def check_file_for_username(username,file='users.txt'):
- with open(file,'r') as f:
- if username in f.read().split('\n'):
- return True
- else:
- return False
- def add_users_from_target(target_subreddit,home_subreddit,password):
- target_sub = re.sub('\/?[rR]\/','',target_subreddit)
- home_sub = re.sub('\/?[rR]\/','',home_subreddit)
- reddit = login(password)
- target_subreddit = reddit.subreddit(target_sub)
- home_subreddit = reddit.subreddit(home_sub)
- total = 0
- for comment in target_subreddit.stream.comments():
- try:
- if not check_file_for_username(comment.author.name):
- now = get_time()
- total += 1
- write_to_file(comment.author.name)
- print("Adding user number {} - /u/{}".format(total,comment.author.name))
- home_subreddit.contributor.add(comment.author.name)
- later = get_time()
- difference = later-now
- print('It took {} seconds to add /u/{} to /r/{}'.format(int(difference), comment.author.name, home_sub))
- else:
- continue
- except Exception as e:
- print(e)
- continue
- def countdown(integer):
- print("Starting in {}".format(integer))
- time.sleep(1)
- interval = list(reversed([i for i in range(integer) if i != 0]))
- for n in interval:
- print(n)
- time.sleep(1)
- def main():
- password=input('Please input password for MyRSSBot: ')
- verify_password=input('Please verify the password above: ')
- if password != verify_password:
- print("Passwords do not match, please try again.")
- time.sleep(3)
- main()
- target = input('Please enter the subreddit you would like to add users from: ')
- home = input("Please enter the subreddit you would like to add them to: ")
- countdown(5)
- add_users_from_target(target,home,password)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement