Guest User

Reddit 24 hour post limit script

a guest
Dec 13th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import praw
  2. import time
  3. from datetime import datetime, timedelta
  4.  
  5. def hours_posted(submission):
  6. """Gets the time that passed (in hours) from when the post was made. (All time is converted to UTC)"""
  7. time_created = submission.created_utc
  8. current_time = datetime.utcnow()
  9. time_posted = datetime.utcfromtimestamp(time_created)
  10. time_difference_in_hours = (current_time - time_posted)/timedelta(hours=1)
  11. return time_difference_in_hours
  12.  
  13. def post_made_today_check(user, link):
  14. """ Returns true if the user who just posted, has already made a previous post within the past 24 hours
  15. Returns false otherwise"""
  16.  
  17. reddit = praw.Reddit(client_id='',
  18. client_secret= '',
  19. user_agent='')
  20.  
  21. subreddit = reddit.subreddit('')
  22. submissions = subreddit.new(limit=50) #Change limit accordingly (max 1000)
  23.  
  24. for submission in submissions:
  25. if link == submission.permalink: # Ignores the post we are checking
  26. continue
  27. #If a post has been made in the past 24 hours by the same user, return true
  28. if user == submission.author.name and hours_posted(submission) < 24:
  29. return True
  30.  
  31. return False
  32.  
  33. if __name__ == "__main__":
  34.  
  35.  
  36. reddit = praw.Reddit(client_id='',
  37. client_secret= '',
  38. user_agent='',
  39. username='',
  40. password=''))
  41.  
  42. subreddit = reddit.subreddit('') #Enter
  43. submissions = subreddit.new(limit=50) #Change limit accordingly (max 1000)
  44. multi_posts_today = False
  45.  
  46. for submission in submissions:
  47. multi_posts_today = post_made_today_check(submission.author.name, submission.permalink)
  48. if multi_posts_today == True:
  49. submission.reply("Enter Reply Here") #replys to post
  50. submission.mod.remove() #Deletes the post
  51. break
Add Comment
Please, Sign In to add comment