SHOW:
|
|
- or go back to the newest paste.
| 1 | - | #!/usr/bin/env python |
| 1 | + | #!/usr/bin/env python2.7 |
| 2 | #-*- coding: Utf-8 -*- | |
| 3 | ||
| 4 | import json | |
| 5 | import urllib2 | |
| 6 | import codecs | |
| 7 | import time | |
| 8 | ||
| 9 | ||
| 10 | def start(url): | |
| 11 | ||
| 12 | compage = urllib2.urlopen(url).read() | |
| 13 | x = json.loads(compage)['data']['children'] | |
| 14 | comcount = len(x) - 1 | |
| 15 | - | |
| 15 | + | |
| 16 | for i in range(0,comcount): | |
| 17 | ##"no more then 30 requests per minute" | |
| 18 | - | |
| 18 | + | time.sleep(60/30) |
| 19 | - | rawdata = "Thread Title: %s\nUrl: http://www.reddit.com/r/%s/%s\n\nComment:\n%s\n\n~------------------------------------------~ \n\n" %(x[i]['data']['link_title'], x[i]['data']['subreddit'], x[i]['data']['link_id'].replace("t3_","").replace("t1_",""), x[i]['data']['body'])
|
| 19 | + | |
| 20 | - | |
| 20 | + | rawdata = x[i]['data']['body'] |
| 21 | ||
| 22 | - | print comments |
| 22 | + | |
| 23 | - | |
| 23 | + | print(comments+"\n\n\n\n") |
| 24 | ||
| 25 | - | |
| 25 | + | |
| 26 | ||
| 27 | nextpageurl = "http://www.reddit.com/user/%s/comments/.json?count=25&after=%s" %(username, x[i]['data']['name']) | |
| 28 | - | |
| 28 | + | |
| 29 | ||
| 30 | if comcount >= 24: | |
| 31 | start(nextpageurl) | |
| 32 | else: | |
| 33 | print "Either finished or messed up somewhere. Check the txt file" | |
| 34 | - | global username |
| 34 | + | |
| 35 | - | username = raw_input("Username:")
|
| 35 | + | global username |
| 36 | username = raw_input("Username:")
| |
| 37 | comurl = "http://www.reddit.com/user/%s/comments/.json" %username | |
| 38 | start(comurl) |