From 5d2551255df405e2eacdb15408c74c4da4ff82d2 Mon Sep 17 00:00:00 2001 From: David Trail Date: Mon, 19 Mar 2012 12:59:21 +0000 Subject: [PATCH] Support for setting the days, whitelist subreddits --- shreddit | 15 +++++++++++++-- shreddit.cfg | 7 +++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 shreddit.cfg diff --git a/shreddit b/shreddit index a73827b..42bb515 100755 --- a/shreddit +++ b/shreddit @@ -1,15 +1,26 @@ #!/usr/bin/env python2 import reddit +import ConfigParser from datetime import datetime, timedelta -r = reddit.Reddit(user_agent="Shreddit-PRAW") +config = ConfigParser.RawConfigParser() +config.read('shreddit.cfg') + +days = config.getint('main', 'days') +whitelist = config.get('main', 'whitelist') +r = reddit.Reddit(user_agent="Shreddit-PRAW") +# add user: / pswd: to the [reddit] config section r.login() -before_time = datetime.now() - timedelta(days=7) +before_time = datetime.now() - timedelta(days=days) + +whitelist = [y.strip().lower() for y in whitelist.split(',')] for comment in r.user.get_comments(limit=None, sort='new'): + if str(comment.subreddit).lower() in whitelist: + next now_time = datetime.fromtimestamp(comment.created) if now_time < before_time: print 'Deleting: [%s]: "%s"' % (comment.subreddit, comment.body[:20]) diff --git a/shreddit.cfg b/shreddit.cfg new file mode 100644 index 0000000..6ad6123 --- /dev/null +++ b/shreddit.cfg @@ -0,0 +1,7 @@ +# User and password will be prompted for +# or can be edited in the reddit_api [reddit] section +[main] +days = 7 + +# Don't delete from these subreddits +whitelist = AskScience, TheCulture, redditdev, sysadmin, programming