Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import time
  2. import praw
  3.  
  4. CONFIG_OLDER_THAN = 4 * 60 * 60 # Minimum submission age in seconds
  5. CONFIG_INTERVAL = 30 * 60 # Refresh interval in seconds
  6. CONFIG_CLIENT_ID = "" # Client ID from /prefs/apps
  7. CONFIG_CLIENT_SECRET = "" # Client secret from /prefs/apps
  8. CONFIG_USERNAME = "" # Username for the bot account
  9. CONFIG_PASSWORD = "" # Password for the bot account
  10. CONFIG_SUBREDDIT = "" # Subreddit the script runs on
  11. CONFIG_SCRIPTHOST = "" # Your Reddit username
  12. CONFIG_USER_AGENT = "autoapprove 1.0 for /r/%s, hosted by /u/%s" \
  13. %(CONFIG_SUBREDDIT, CONFIG_SCRIPTHOST)
  14.  
  15. def within_period(time1, time2):
  16. v = time1 - time2
  17. if CONFIG_OLDER_THAN > v: return 1
  18. elif v > (CONFIG_OLDER_THAN + CONFIG_INTERVAL): return 2
  19. return 0
  20.  
  21. def log(msg):
  22. print('[%s] %s'%(time.ctime(), msg))
  23.  
  24. def main():
  25. reddit = praw.Reddit(client_id = CONFIG_CLIENT_ID,
  26. client_secret = CONFIG_CLIENT_SECRET,
  27. username = CONFIG_USERNAME,
  28. password = CONFIG_PASSWORD,
  29. user_agent = CONFIG_USER_AGENT)
  30. while True:
  31. log('Scanning subreddit...')
  32. curtime = time.time()
  33. sub = reddit.subreddit(CONFIG_SUBREDDIT)
  34. apprv = 0
  35. for post in sub.new():
  36. create = within_period(curtime, post.created_utc)
  37. if create == 2: break
  38. if create == 1: continue
  39. if post.num_reports == 0 and not post.spam and not \
  40. post.approved and not post.removed:
  41. post.mod.approve()
  42. log('Approved post by /u/%s!'%post.author)
  43. nextiter = curtime + CONFIG_INTERVAL
  44. wait = (nextiter - time.time())
  45. if wait > 0:
  46. log('Sleeping for %d seconds.'%wait)
  47. time.sleep(wait)
  48.  
  49. if __name__ == '__main__':
  50. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement