|
|
|
#!/usr/bin/env python2
|
|
|
|
|
|
|
|
import reddit
|
|
|
|
import ConfigParser
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
config = ConfigParser.RawConfigParser()
|
|
|
|
config.read('shreddit.cfg')
|
|
|
|
|
|
|
|
days = config.getint('main', 'days')
|
|
|
|
whitelist = config.get('main', 'whitelist')
|
|
|
|
sort = config.get('main', 'sort')
|
|
|
|
verbose = config.getboolean('main', 'verbose')
|
|
|
|
clear_vote = config.getboolean('main', 'clear_vote')
|
|
|
|
item = config.get('main', 'item')
|
|
|
|
|
|
|
|
r = reddit.Reddit(user_agent="Shreddit-PRAW")
|
|
|
|
# add user: <YourUsername> / pswd: <YourPassword> to the [reddit] config section
|
|
|
|
r.login()
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
print "Logged in as %s" % r.user
|
|
|
|
|
|
|
|
before_time = datetime.now() - timedelta(days=days)
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
print "Deleting messages before %s" % before_time
|
|
|
|
|
|
|
|
whitelist = [y.strip().lower() for y in whitelist.split(',')]
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
print "Keeping messages from subreddits %s" % ', '.join(whitelist)
|
|
|
|
|
|
|
|
delete_whitelist = ('comments', 'submitted')
|
|
|
|
if item not in delete_whitelist:
|
|
|
|
raise Exception("Your deletion section is wrong")
|
|
|
|
|
|
|
|
things = []
|
|
|
|
if item == "comments":
|
|
|
|
things = r.user.get_comments(limit=None, sort=sort)
|
|
|
|
elif item == "submitted":
|
|
|
|
things = r.user.get_submitted(limit=None, sort=sort)
|
|
|
|
|
|
|
|
for thing in things:
|
|
|
|
if item == "submitted":
|
|
|
|
if verbose:
|
|
|
|
print thing
|
|
|
|
thing.delete()
|
|
|
|
continue
|
|
|
|
if str(thing.subreddit).lower() in whitelist:
|
|
|
|
continue
|
|
|
|
now_time = datetime.fromtimestamp(thing.created)
|
|
|
|
if now_time < before_time:
|
|
|
|
if verbose:
|
|
|
|
print 'Deleting: [%s]: "%s"' % (thing.subreddit, thing.body[:20])
|
|
|
|
if clear_vote:
|
|
|
|
thing.clear_vote()
|
|
|
|
thing.delete()
|