Created
June 19, 2016 20:18
-
-
Save Balletie/c91c44ce883f8a1ed11fe084cdbb1746 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import praw | |
import textwrap | |
import types | |
from HTMLParser import HTMLParser | |
wrapper = textwrap.TextWrapper(width=100, break_long_words=False, replace_whitespace=False) | |
h = HTMLParser() | |
def print_comment_term(comment, level): | |
if isinstance(comment.author, types.NoneType): | |
author = "[deleted]" | |
else: | |
author = comment.author.name | |
print(' | '*level,'Username: ',author,', Score: ',`comment.score`,sep='') | |
print(' | '*level,'Permalink: '+comment.permalink,sep='') | |
wrapper.initial_indent=' | '*level + "Text: " | |
wrapper.subsequent_indent=' | '*(level + 2) | |
print(wrapper.fill(h.unescape(comment.body)).encode('ascii','ignore')) | |
print(wrapper.fill(comment.body.encode('ascii','ignore'))) | |
print(' | '*(level + 1)) | |
def print_comment(comment, level): | |
if isinstance(comment.author, types.NoneType): | |
author = "[deleted]" | |
else: | |
author = comment.author.name | |
print('<pre>', 'Username: ',author,', Score: ',`comment.score`,sep='') | |
print('Permalink: <a href=\"', | |
comment.permalink.encode('ascii','ignore'), | |
'\">Link</a>', | |
', Thread link: <a href=\"', | |
comment.submission.short_link, | |
'\">', | |
comment.submission.title.encode('ascii','ignore'), | |
'</a>', | |
', <a href=\"#\" onclick=\"return hide(this);\">[-]</a>' if level==0 else "", | |
'</pre>',sep='') | |
print(h.unescape(comment.body_html.encode('ascii','ignore'))) | |
def print_tree(commentTree, level, maxlevel=None): | |
if maxlevel == None: | |
maxlevel=10 | |
if level == maxlevel: | |
return | |
print('<div class=\"allnested\">') | |
for comment in commentTree: | |
print('<div class=\"nested\">') | |
print_comment(comment,level) | |
print_tree(comment.replies, level + 1, maxlevel) | |
print('</div>') | |
print('</div>') | |
r = praw.Reddit('commentfetcher by Skipperr') | |
#submission = r.get_submission(submission_id='1xcy87') | |
#comments = submission.comments | |
#print_tree(comments, 0, 4) | |
redditor = r.get_redditor("michael_dorfman") | |
m_comments = redditor.get_comments(limit=10000) | |
print('<html><head>', | |
'<link href=\"stylesheet.css\" rel=\"stylesheet\" type=\"text/css\"/>', | |
'<script src=\"showhide.js\"></script>', | |
'</head><body><a onclick=\"return hideAll()\" href=\"#\">Hide All</a><div>') | |
for comment in m_comments: | |
if comment.parent_id == comment.link_id: | |
print('<div class=\"root\">') | |
print_comment(comment, 0) | |
print_tree(comment.replies, 1) | |
print('</div>') | |
print('</div></body></html>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFirstChild(el) { | |
var firstChild = el.firstChild; | |
while (firstChild != null && firstChild.nodeType == 3) { // skip TextNodes | |
firstChild = firstChild.nextSibling; | |
} | |
return firstChild; | |
} | |
function getNextSibling(e) { | |
while (e && (e = e.nextSibling)) { | |
if (e.nodeType == 1) { | |
return e | |
} | |
} | |
return undefined | |
} | |
function hideAll() { | |
hide_nested = document.querySelectorAll(".root>.allnested"); | |
hide_rootmd = document.querySelectorAll(".root>.md"); | |
for (var i = 0; i < hide_nested.length; i++) { | |
hide_nested[i].style.display = "none"; | |
hide_rootmd[i].style.display = "none"; | |
} | |
getFirstChild(document.body).innerHTML = "Show All"; | |
getFirstChild(document.body).setAttribute("onclick", "return showAll()"); | |
return true; | |
} | |
function showAll() { | |
show_nested = document.querySelectorAll(".root>.allnested"); | |
show_rootmd = document.querySelectorAll(".root>.md"); | |
for (var i = 0; i < hide_nested.length; i++) { | |
show_nested[i].style.display = "block"; | |
show_rootmd[i].style.display = "block"; | |
} | |
getFirstChild(document.body).innerHTML = "Hide All"; | |
getFirstChild(document.body).setAttribute("onclick", "return hideAll()"); | |
return true; | |
} | |
function hide(e) { | |
pre = e.parentNode; | |
md = getNextSibling(pre); | |
md.style.display = "none"; | |
allnested = getNextSibling(md); | |
allnested.style.display = "none"; | |
e.innerHTML = "[+]"; | |
e.setAttribute("onclick", "return show(this)"); | |
return true | |
} | |
function show(e) { | |
pre = e.parentNode; | |
md = getNextSibling(pre); | |
md.style.display = "block"; | |
allnested = getNextSibling(md); | |
allnested.style.display = "block"; | |
e.innerHTML = "[-]"; | |
e.setAttribute("onclick", "return hide(this)"); | |
return true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 0px 0px 0px 0px; | |
} | |
body>div { | |
width:70%; | |
margin: 0 auto 30px auto; | |
border-left: solid 1px; | |
border-right:solid 1px; | |
} | |
body>a { | |
position: fixed; | |
} | |
blockquote>p { | |
border-left: solid 3px; | |
padding-left: 2px; | |
background-color: #E2E2E2; | |
} | |
.nested { | |
margin: 2px 2px 2px 20px; | |
border:solid 1px; | |
} | |
.root { | |
padding: 2px 0px 0px 0px; | |
border-bottom: solid 1px; | |
} | |
pre { | |
margin: 0px 0px 0px 10px; | |
overflow-x: auto; | |
} | |
.md>blockquote { | |
margin-left: 15px; | |
} | |
.md>p { | |
margin-left: 10px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment