Advertisement
Guest User

Example Bot

a guest
Nov 29th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. import praw
  2. import json
  3.  
  4. # What position on r/all would you like to post the comment on?
  5. notificationThreshold = 100
  6.  
  7. # What subreddit?
  8. subreddit = 'pcmasterrace'
  9.  
  10. # The message you want to send.  Use Reddit formatting here.
  11. allMessage = """Hey, this is on r/all.
  12. [Read the rules you numpties.](/r/pcmasterrace/about/rules)"""
  13.  
  14. # http://praw.readthedocs.io/en/v4.0.0/getting_started/authentication.html?highlight=oauth
  15. # You will definitely have to change this.  See the above link for instructions
  16.  
  17. auth = []
  18. auth['client_id'] = 'SI8pN3DSbt0zor'
  19. auth['client_secret'] = 'xaxkj7HNh8kwg8e5t4m6KvSrbTI'
  20. auth['user_agent'] = 'testscript by /u/fakebot3'
  21. auth['username'] = 'fakebot3'
  22. auth['password'] = '1guiwevlfo00esyy'
  23.  
  24. reddit = praw.Reddit(client_id= auth['client_id'],
  25.                      client_secret= auth['client_secret'],
  26.                      password= auth['password'],
  27.                      user_agent= auth['user_agent'],
  28.                      username= auth['username'])
  29.  
  30. f = open('./seenFrontPagePosts.txt', 'r+')
  31. try:
  32.     frontOld = json.loads(f.readline())
  33. except:
  34.     frontOld = []
  35.  
  36. # Get the top N posts from Reddit.  N is notificationThreshold
  37. redditFrontPage = reddit.get_subreddit('all') \
  38.                         .get_hot(limit=notificationThreshold)
  39.  
  40. # Loop through each post
  41. for post in redditFrontPage:
  42.     # See if the subreddit that the post is in is the subreddit
  43.     # we care about.
  44.     if str(post.subreddit) is subreddit:
  45.         print "We have a post on r/all!"
  46.         if str(post.id) not in frontOld:
  47.             print "We haven't seen it before!"
  48.             message = post.reply(allMessage)
  49.             message.distinguish(sticky=True)
  50.             frontOld.append(str(post.id))
  51.  
  52. f.seek(0)
  53. f.truncate()
  54. f.seek(0)
  55. f.write(json.dumps(frontOld))
  56. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement