From 32d1690eb45ddef5e71138c1dd10aca18a0a8932 Mon Sep 17 00:00:00 2001 From: David Trail Date: Mon, 19 Mar 2012 00:15:03 +0100 Subject: [PATCH] All working now --- grab.py | 5 +++-- kill.py | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/grab.py b/grab.py index 83108d1..5c9a063 100755 --- a/grab.py +++ b/grab.py @@ -29,13 +29,14 @@ datum = [] while True: after = reddit['data']['after'] children = reddit['data']['children'] + # This bit fills datum with the id (for removal) and the date (for saving recent posts) for child in children: child_data = child['data'] if 'id' in child_data: datum.append({ - 'id': child_data[u'id'], + 'id': child_data[u'name'], 'created': child_data['created'], 'body': child_data['body'], 'subreddit': child_data['subreddit']}) @@ -46,7 +47,7 @@ while True: next_url = init_url % after http = urlopen(next_url) reddit = json.load(http) - sleep(1) # don't want to hammer reddit to hard + sleep(1) f = open('data.json', 'w') json.dump(datum, f) diff --git a/kill.py b/kill.py index 3a17b31..24a0e80 100755 --- a/kill.py +++ b/kill.py @@ -34,12 +34,16 @@ if len(deletion_ids) == 0: ## This part logs you in. -headers = {"Content-type": "application/x-www-form-urlencoded"} +headers = { + "Content-type": "application/x-www-form-urlencoded", + "User-Agent": "Shreddit" + } conn = httplib.HTTPSConnection('ssl.reddit.com') params = urllib.urlencode({ 'user': user, 'passwd': passwd, 'api_type': 'json'}) + conn.request("POST", "/api/login/%s" % user, params, headers) http = conn.getresponse() tmp = json.loads(http.read())['json']['data'] @@ -52,16 +56,16 @@ for dat in deletion_ids: subreddit = dat['subreddit'] text = dat[u'body'][:20] - print '{id}: {time} {subreddit}: "{text}..."'.format(subreddit=subreddit, id=id, time=time, text=text) + #print '{id}: {time} {subreddit}: "{text}..."'.format(subreddit=subreddit, id=id, time=time, text=text) # And now for the deleting conn = httplib.HTTPConnection('www.reddit.com') params = urllib.urlencode({ 'id': id, 'uh': modhash, 'api_type': 'json'}) + #headers.update({"Content-Length": len(params)}) conn.request('POST', '/api/del', params, headers) http = conn.getresponse() - print http.read() - #print '''Failed to delete "%s" (%s - %s - %s)''' % (text, id, time, subreddit) - break + if http.read() != '{}': + print '''Failed to delete "%s" (%s - %s - %s)''' % (text, id, time, subreddit) sleep(2)