Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import praw
- CONFIG_OLDER_THAN = 4 * 60 * 60 # Minimum submission age in seconds
- CONFIG_INTERVAL = 30 * 60 # Refresh interval in seconds
- CONFIG_CLIENT_ID = "" # Client ID from /prefs/apps
- CONFIG_CLIENT_SECRET = "" # Client secret from /prefs/apps
- CONFIG_USERNAME = "" # Username for the bot account
- CONFIG_PASSWORD = "" # Password for the bot account
- CONFIG_SUBREDDIT = "" # Subreddit the script runs on
- CONFIG_SCRIPTHOST = "" # Your Reddit username
- CONFIG_USER_AGENT = "autoapprove 1.0 for /r/%s, hosted by /u/%s" \
- %(CONFIG_SUBREDDIT, CONFIG_SCRIPTHOST)
- def within_period(time1, time2):
- v = time1 - time2
- if CONFIG_OLDER_THAN > v: return 1
- elif v > (CONFIG_OLDER_THAN + CONFIG_INTERVAL): return 2
- return 0
- def log(msg):
- print('[%s] %s'%(time.ctime(), msg))
- def main():
- reddit = praw.Reddit(client_id = CONFIG_CLIENT_ID,
- client_secret = CONFIG_CLIENT_SECRET,
- username = CONFIG_USERNAME,
- password = CONFIG_PASSWORD,
- user_agent = CONFIG_USER_AGENT)
- while True:
- log('Scanning subreddit...')
- curtime = time.time()
- sub = reddit.subreddit(CONFIG_SUBREDDIT)
- apprv = 0
- for post in sub.new():
- create = within_period(curtime, post.created_utc)
- if create == 2: break
- if create == 1: continue
- if post.num_reports == 0 and not post.spam and not \
- post.approved and not post.removed:
- post.mod.approve()
- log('Approved post by /u/%s!'%post.author)
- nextiter = curtime + CONFIG_INTERVAL
- wait = (nextiter - time.time())
- if wait > 0:
- log('Sleeping for %d seconds.'%wait)
- time.sleep(wait)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement