Merge branch 'morecomment-speed'
This commit is contained in:
@@ -19,7 +19,6 @@ from .__version__ import __version__
|
|||||||
|
|
||||||
__all__ = []
|
__all__ = []
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
"""
|
"""
|
||||||
Search for a configuration file at the location ~/.rtv and attempt to load
|
Search for a configuration file at the location ~/.rtv and attempt to load
|
||||||
@@ -98,13 +97,15 @@ def main():
|
|||||||
|
|
||||||
config.unicode = args.unicode
|
config.unicode = args.unicode
|
||||||
|
|
||||||
|
# Squelch SSL warnings for Ubuntu
|
||||||
|
logging.captureWarnings(True)
|
||||||
if args.log:
|
if args.log:
|
||||||
logging.basicConfig(level=logging.DEBUG, filename=args.log)
|
logging.basicConfig(level=logging.DEBUG, filename=args.log)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print('Connecting...')
|
print('Connecting...')
|
||||||
reddit = praw.Reddit(user_agent=AGENT)
|
reddit = praw.Reddit(user_agent=AGENT)
|
||||||
reddit.config.decode_html_entities = True
|
reddit.config.decode_html_entities = False
|
||||||
if args.username:
|
if args.username:
|
||||||
# PRAW will prompt for password if it is None
|
# PRAW will prompt for password if it is None
|
||||||
reddit.login(args.username, args.password)
|
reddit.login(args.username, args.password)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import textwrap
|
import textwrap
|
||||||
|
import logging
|
||||||
|
|
||||||
import praw
|
import praw
|
||||||
import requests
|
import requests
|
||||||
@@ -8,6 +9,7 @@ from .helpers import humanize_timestamp, wrap_text, strip_subreddit_url
|
|||||||
|
|
||||||
__all__ = ['SubredditContent', 'SubmissionContent']
|
__all__ = ['SubredditContent', 'SubmissionContent']
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class BaseContent(object):
|
class BaseContent(object):
|
||||||
|
|
||||||
@@ -41,14 +43,22 @@ class BaseContent(object):
|
|||||||
retval = []
|
retval = []
|
||||||
while stack:
|
while stack:
|
||||||
item = stack.pop(0)
|
item = stack.pop(0)
|
||||||
if isinstance(item, praw.objects.MoreComments) and (
|
if isinstance(item, praw.objects.MoreComments):
|
||||||
item.count == 0):
|
if item.count == 0:
|
||||||
continue
|
# MoreComments item count should never be zero, but if it
|
||||||
nested = getattr(item, 'replies', None)
|
# is then discard the MoreComment object. Need to look into
|
||||||
if nested:
|
# this further.
|
||||||
for n in nested:
|
continue
|
||||||
n.nested_level = item.nested_level + 1
|
else:
|
||||||
stack[0:0] = nested
|
if item._replies is None:
|
||||||
|
# Attach children MoreComment replies to parents
|
||||||
|
# https://github.com/praw-dev/praw/issues/391
|
||||||
|
item._replies = [stack.pop(0)]
|
||||||
|
nested = getattr(item, 'replies', None)
|
||||||
|
if nested:
|
||||||
|
for n in nested:
|
||||||
|
n.nested_level = item.nested_level + 1
|
||||||
|
stack[0:0] = nested
|
||||||
retval.append(item)
|
retval.append(item)
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
@@ -120,7 +130,7 @@ class SubmissionContent(BaseContent):
|
|||||||
list for repeat access.
|
list for repeat access.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, submission, loader, indent_size=2, max_indent_level=4):
|
def __init__(self, submission, loader, indent_size=2, max_indent_level=8):
|
||||||
|
|
||||||
self.indent_size = indent_size
|
self.indent_size = indent_size
|
||||||
self.max_indent_level = max_indent_level
|
self.max_indent_level = max_indent_level
|
||||||
@@ -133,7 +143,7 @@ class SubmissionContent(BaseContent):
|
|||||||
self._comment_data = [self.strip_praw_comment(c) for c in comments]
|
self._comment_data = [self.strip_praw_comment(c) for c in comments]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_url(cls, reddit, url, loader, indent_size=2, max_indent_level=4):
|
def from_url(cls, reddit, url, loader, indent_size=2, max_indent_level=8):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with loader():
|
with loader():
|
||||||
@@ -210,7 +220,7 @@ class SubmissionContent(BaseContent):
|
|||||||
|
|
||||||
elif data['type'] == 'MoreComments':
|
elif data['type'] == 'MoreComments':
|
||||||
with self._loader():
|
with self._loader():
|
||||||
comments = data['object'].comments(update=False)
|
comments = data['object'].comments(update=True)
|
||||||
comments = self.flatten_comments(comments,
|
comments = self.flatten_comments(comments,
|
||||||
root_level=data['level'])
|
root_level=data['level'])
|
||||||
comment_data = [self.strip_praw_comment(c) for c in comments]
|
comment_data = [self.strip_praw_comment(c) for c in comments]
|
||||||
|
|||||||
Reference in New Issue
Block a user