Last active
April 24, 2020 15:46
-
-
Save ty-porter/395b6088c5ae015a1b3c579285da356d to your computer and use it in GitHub Desktop.
Bot to only allow posts to exist for 15 minutes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import praw | |
import traceback | |
import sys | |
BOT_USERNAME = 'BOT_USERNAME' | |
BOT_PASSWORD = 'BOT_PASSWORD' | |
BOT_CLIENT_ID = 'BOT_CLIENT_ID' | |
BOT_CLIENT_SECRET = 'BOT_CLIENT_SECRET' | |
BOT_USER_AGENT = 'BOT_USER_AGENT' | |
SUBREDDIT = 'SUBREDDIT' | |
TIME_LIMIT = 15 | |
reddit = praw.Reddit(username=BOT_USERNAME, | |
password=BOT_PASSWORD, | |
client_id=BOT_CLIENT_ID, | |
client_secret=BOT_CLIENT_SECRET, | |
user_agent=BOT_USER_AGENT) | |
def run(): | |
for submission in reddit.subreddit(SUBREDDIT).submissions(): | |
if time_diff_in_seconds(submssion) > seconds(TIME_LIMIT): | |
submission.mod.remove() | |
def time_diff_in_seconds(submission): | |
submission_time = datetime.datetime.utcfromtimestamp(submission.created_utc) | |
current_time = datetime.datetime.utcnow() | |
return (current_time - submission_time).seconds | |
def seconds(number): | |
return number * 60 | |
if __name__ == '__main__': | |
try: | |
run() | |
sleep(30) | |
except KeyboardInterrupt: | |
sys.exit(0) | |
except Exception: | |
traceback.print_exc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment