Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2.7
- #-*- coding: Utf-8 -*-
- import json
- import urllib2
- import codecs
- import time
- def start(url):
- compage = urllib2.urlopen(url).read()
- x = json.loads(compage)['data']['children']
- comcount = len(x) - 1
- comfile = open("%s.txt"%username, 'a')
- for i in range(0,comcount):
- ##"no more then 30 requests per minute"
- time.sleep(60/30)
- rawdata = x[i]['data']['body']
- comments = rawdata.encode('utf-8')
- print(comments+"\n\n\n\n")
- comfile.write(comments)
- nextpageurl = "http://www.reddit.com/user/%s/comments/.json?count=25&after=%s" %(username, x[i]['data']['name'])
- comfile.close()
- if comcount >= 24:
- start(nextpageurl)
- else:
- print "Either finished or messed up somewhere. Check the txt file"
- global username
- username = raw_input("Username:")
- comurl = "http://www.reddit.com/user/%s/comments/.json" %username
- start(comurl)
Add Comment
Please, Sign In to add comment