mirror of https://github.com/x89/Shreddit
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.9 KiB
76 lines
1.9 KiB
#!/usr/bin/env python2
|
|
|
|
import praw
|
|
import ConfigParser
|
|
from datetime import datetime, timedelta
|
|
|
|
config = ConfigParser.RawConfigParser()
|
|
config.read('shreddit.cfg')
|
|
|
|
hours = config.getint('main', 'hours')
|
|
whitelist = config.get('main', 'whitelist')
|
|
whitelist_ids = config.get('main', 'whitelist_ids')
|
|
sort = config.get('main', 'sort')
|
|
verbose = config.getboolean('main', 'verbose')
|
|
clear_vote = config.getboolean('main', 'clear_vote')
|
|
item = config.get('main', 'item')
|
|
|
|
_user = config.get('main', 'username')
|
|
_pass = config.get('main', 'password')
|
|
|
|
r = praw.Reddit(user_agent="Shreddit-PRAW 2.0")
|
|
|
|
if _user and _pass:
|
|
r.login(_user, _pass)
|
|
else:
|
|
r.login()
|
|
|
|
if verbose:
|
|
print "Logged in as %s" % r.user
|
|
|
|
before_time = datetime.now() - timedelta(hours=hours)
|
|
|
|
if verbose:
|
|
print "Deleting messages before %s" % before_time
|
|
|
|
whitelist = [y.strip().lower() for y in whitelist.split(',')]
|
|
whitelist_ids = [y.strip().lower() for y in whitelist_ids.split(',')]
|
|
|
|
if verbose:
|
|
print "Keeping messages from subreddits %s" % ', '.join(whitelist)
|
|
|
|
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)
|
|
elif item == "overview":
|
|
things = r.user.get_overview(limit=None, sort=sort)
|
|
else:
|
|
raise Exception("Your deletion section is wrong")
|
|
|
|
for thing in things:
|
|
thing_time = datetime.fromtimestamp(thing.created)
|
|
|
|
#print "%s, %s, %s" % (thing_time, before_time, thing_time < before_time)
|
|
|
|
if thing.id in whitelist_ids:
|
|
continue
|
|
|
|
if thing_time > before_time:
|
|
continue
|
|
|
|
if str(thing.subreddit).lower() in whitelist:
|
|
continue
|
|
|
|
if item == "submitted" or item == "overview":
|
|
if verbose:
|
|
print "Deleting: %s" % thing
|
|
thing.delete()
|
|
elif item == "comments":
|
|
if verbose:
|
|
print 'Deleting: [%s]: "%s"' % (thing.subreddit, thing.body[:20])
|
|
if clear_vote:
|
|
thing.clear_vote()
|
|
thing.delete()
|