Restructuring a little.

nopraw
David Trail 13 years ago
parent 9a725fa06e
commit 26f2130342

@ -8,7 +8,7 @@ obscure the author (replaces with [deleted]) which is not good enough for some p
Usage Usage
----------- -----------
python2 shreddit.py UserName ./shreddit UserName
Caveats Caveats
----------- -----------

@ -2,7 +2,7 @@
import sys import sys
from json import loads, dumps from json import loads, dumps
from urllib2 import urlopen from urllib2 import urlopen, HTTPError
from time import sleep from time import sleep
if len(sys.argv) != 2: 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) init_url = 'http://www.reddit.com/user/{user}/comments/.json?after=%s'.format(user=user)
next_url = init_url % after next_url = init_url % after
http = urlopen(next_url).read() try:
json = loads(http) 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 = [] datum = []
while True: while True:
print "Grabing IDs for after: ", after
after = json['data']['after'] after = json['data']['after']
children = json['data']['children'] children = json['data']['children']
@ -37,9 +43,7 @@ while True:
next_url = init_url % after next_url = init_url % after
http = urlopen(next_url).read() http = urlopen(next_url).read()
json = loads(http) json = loads(http)
sleep(2) # don't want to hammer reddit to hard sleep(1) # don't want to hammer reddit to hard
print "Script collected all available data."
f = open('data.json', 'w') f = open('data.json', 'w')
f.write(dumps(datum)) f.write(dumps(datum))

@ -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."
Loading…
Cancel
Save