import praw, json, textwrap from time import sleep from prawcore import NotFound import datetime as dt reddit = praw.Reddit() HTMLHEAD = 'htmlhead.html' def sub_exists(sub): exists = True try: reddit.subreddits.search_by_name(sub, exact=True) except NotFound: exists = False return exists def formatstr(s): try: return s.encode('ascii', errors='ignore').decode() except: return '

ENCODING ERROR

' def bar(amount, total, width, unit=''): left = int(width/total*amount) right = width-left-1 if (left >= width): print('\r['+'='*width+'] '+str(amount)+'/'+str(total)+('' if unit == '' else ' '+unit)+' ('+str(round(amount/total*100, 1))+'%)', end='') return print('\r['+'='*left+'>'+' '*right+'] '+str(amount)+'/'+str(total)+('' if unit == '' else ' '+unit)+' ('+str(round(amount/total*100, 1))+'%)', end='') print('Subreddit Scrapper by Brendan Westley') f = open(HTMLHEAD, 'r') head = f.read() f.close() subname = input('Subreddit: ') or 'entitledparents' if False:#sub_exists(subname): print('Sub', subname, 'does not exist.') else: numitems = int(input('Number of items: ') or 10) fn = input('Filename (default htmldump.html): ') or 'htmldump.html' subreddit = reddit.subreddit(subname) f = open(fn, 'w') i = 0 print('Retreving') f.write(head+'') for post in subreddit.hot(limit=numitems): bar(i, numitems, 30, 'posts') i += 1 html = ('') f.write('\n') f.close()