diff --git a/README.rst b/README.rst index 3ba56d9..fd225d7 100644 --- a/README.rst +++ b/README.rst @@ -8,7 +8,7 @@ obscure the author (replaces with [deleted]) which is not good enough for some p Usage ----------- -python2 shreddit.py UserName +./shreddit UserName Caveats ----------- diff --git a/grab.py b/grab.py index 6392c34..664fb85 100755 --- a/grab.py +++ b/grab.py @@ -2,7 +2,7 @@ import sys from json import loads, dumps -from urllib2 import urlopen +from urllib2 import urlopen, HTTPError from time import sleep if len(sys.argv) != 2: @@ -16,12 +16,18 @@ after = '' init_url = 'http://www.reddit.com/user/{user}/comments/.json?after=%s'.format(user=user) next_url = init_url % after -http = urlopen(next_url).read() -json = loads(http) +try: + http = urlopen(next_url).read() +except HTTPError: + raise HTTPError("You seem to have given an invalid user") + +try: + json = loads(http) +except ValueError: + raise ValueError("Failed to decode json.") datum = [] while True: - print "Grabing IDs for after: ", after after = json['data']['after'] children = json['data']['children'] @@ -37,9 +43,7 @@ while True: next_url = init_url % after http = urlopen(next_url).read() json = loads(http) - sleep(2) # don't want to hammer reddit to hard - -print "Script collected all available data." + sleep(1) # don't want to hammer reddit to hard f = open('data.json', 'w') f.write(dumps(datum)) diff --git a/shreddit b/shreddit new file mode 100755 index 0000000..eae3a66 --- /dev/null +++ b/shreddit @@ -0,0 +1,19 @@ +#!/bin/sh + +USER=$1 + +if [ $2 ]; then + DAYS=$2 +else + DAYS=7 +fi + +echo "Deleting everything before $DAYS days ago for user $USER" + +echo "Running grab.py to get your history..." +python2 grab.py $USER || exit 1 + +echo "Running kill.py to annihilate your history..." +python2 kill.py $DAYS || exit 1 + +echo "Everything seemed to run successfully."