Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import json
- # What position on r/all would you like to post the comment on?
- notificationThreshold = 100
- # What subreddit?
- subreddit = 'pcmasterrace'
- # The message you want to send. Use Reddit formatting here.
- allMessage = """Hey, this is on r/all.
- [Read the rules you numpties.](/r/pcmasterrace/about/rules)"""
- # http://praw.readthedocs.io/en/v4.0.0/getting_started/authentication.html?highlight=oauth
- # You will definitely have to change this. See the above link for instructions
- auth = []
- auth['client_id'] = 'SI8pN3DSbt0zor'
- auth['client_secret'] = 'xaxkj7HNh8kwg8e5t4m6KvSrbTI'
- auth['user_agent'] = 'testscript by /u/fakebot3'
- auth['username'] = 'fakebot3'
- auth['password'] = '1guiwevlfo00esyy'
- reddit = praw.Reddit(client_id= auth['client_id'],
- client_secret= auth['client_secret'],
- password= auth['password'],
- user_agent= auth['user_agent'],
- username= auth['username'])
- f = open('./seenFrontPagePosts.txt', 'r+')
- try:
- frontOld = json.loads(f.readline())
- except:
- frontOld = []
- # Get the top N posts from Reddit. N is notificationThreshold
- redditFrontPage = reddit.get_subreddit('all') \
- .get_hot(limit=notificationThreshold)
- # Loop through each post
- for post in redditFrontPage:
- # See if the subreddit that the post is in is the subreddit
- # we care about.
- if str(post.subreddit) is subreddit:
- print "We have a post on r/all!"
- if str(post.id) not in frontOld:
- print "We haven't seen it before!"
- message = post.reply(allMessage)
- message.distinguish(sticky=True)
- frontOld.append(str(post.id))
- f.seek(0)
- f.truncate()
- f.seek(0)
- f.write(json.dumps(frontOld))
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement