mirror of
https://github.com/instaloader/instaloader.git
synced 2024-11-23 02:32:46 +01:00
Remove needlessly complicated code
This commit is contained in:
parent
15d9cd8949
commit
0fd06fe6bc
@ -122,8 +122,6 @@ Additionally, the following trivial structures are defined:
|
|||||||
|
|
||||||
.. autoclass:: PostComment
|
.. autoclass:: PostComment
|
||||||
:no-show-inheritance:
|
:no-show-inheritance:
|
||||||
:inherited-members:
|
|
||||||
:exclude-members: count, index
|
|
||||||
|
|
||||||
.. autoclass:: PostCommentAnswer
|
.. autoclass:: PostCommentAnswer
|
||||||
:no-show-inheritance:
|
:no-show-inheritance:
|
||||||
|
@ -4,8 +4,6 @@ import re
|
|||||||
from base64 import b64decode, b64encode
|
from base64 import b64decode, b64encode
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import reduce
|
|
||||||
from operator import add
|
|
||||||
from typing import Any, Dict, Iterator, List, Optional, Union
|
from typing import Any, Dict, Iterator, List, Optional, Union
|
||||||
|
|
||||||
from . import __version__
|
from . import __version__
|
||||||
@ -25,6 +23,11 @@ PostCommentAnswer.created_at_utc.__doc__ = ":class:`~datetime.datetime` when com
|
|||||||
PostCommentAnswer.text.__doc__ = "Comment text."
|
PostCommentAnswer.text.__doc__ = "Comment text."
|
||||||
PostCommentAnswer.owner.__doc__ = "Owner :class:`Profile` of the comment."
|
PostCommentAnswer.owner.__doc__ = "Owner :class:`Profile` of the comment."
|
||||||
|
|
||||||
|
PostComment = namedtuple('PostComment', (*PostCommentAnswer._fields, 'answers'))
|
||||||
|
for field in PostCommentAnswer._fields:
|
||||||
|
getattr(PostComment, field).__doc__ = getattr(PostCommentAnswer, field).__doc__
|
||||||
|
PostComment.answers.__doc__ = r"Iterator which yields all :class:`PostCommentAnswer`\ s for the comment."
|
||||||
|
|
||||||
PostLocation = namedtuple('PostLocation', ['id', 'name', 'slug', 'has_public_page', 'lat', 'lng'])
|
PostLocation = namedtuple('PostLocation', ['id', 'name', 'slug', 'has_public_page', 'lat', 'lng'])
|
||||||
PostLocation.id.__doc__ = "ID number of location."
|
PostLocation.id.__doc__ = "ID number of location."
|
||||||
PostLocation.name.__doc__ = "Location name."
|
PostLocation.name.__doc__ = "Location name."
|
||||||
@ -34,21 +37,6 @@ PostLocation.lat.__doc__ = "Latitude (:class:`float`)."
|
|||||||
PostLocation.lng.__doc__ = "Longitude (:class:`float`)."
|
PostLocation.lng.__doc__ = "Longitude (:class:`float`)."
|
||||||
|
|
||||||
|
|
||||||
class PostComment(namedtuple('PostComment', (*PostCommentAnswer._fields, 'answers'))):
|
|
||||||
__slots__ = ()
|
|
||||||
|
|
||||||
def __new__(cls, pca: PostCommentAnswer, answers: Iterator[PostCommentAnswer]):
|
|
||||||
return super(cls, PostComment).__new__(cls,
|
|
||||||
*(getattr(pca, field) for field in PostCommentAnswer._fields),
|
|
||||||
answers)
|
|
||||||
|
|
||||||
|
|
||||||
PostComment.__doc__ = PostComment.__bases__[0].__doc__
|
|
||||||
for field in PostCommentAnswer._fields:
|
|
||||||
getattr(PostComment, field).__doc__ = getattr(PostCommentAnswer, field).__doc__
|
|
||||||
PostComment.answers.__doc__ = r"Iterator which yields all :class:`PostCommentAnswer`\ s for the comment."
|
|
||||||
|
|
||||||
|
|
||||||
class Post:
|
class Post:
|
||||||
"""
|
"""
|
||||||
Structure containing information about an Instagram post.
|
Structure containing information about an Instagram post.
|
||||||
@ -338,14 +326,14 @@ class Post:
|
|||||||
lambda d: d['data']['comment']['edge_threaded_comments']))
|
lambda d: d['data']['comment']['edge_threaded_comments']))
|
||||||
|
|
||||||
def _postcomment(node):
|
def _postcomment(node):
|
||||||
return PostComment(_postcommentanswer(node),
|
return PostComment(*_postcommentanswer(node),
|
||||||
answers=_postcommentanswers(node))
|
answers=_postcommentanswers(node))
|
||||||
if self.comments == 0:
|
if self.comments == 0:
|
||||||
# Avoid doing additional requests if there are no comments
|
# Avoid doing additional requests if there are no comments
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
comment_edges = self._field('edge_media_to_parent_comment', 'edges')
|
comment_edges = self._field('edge_media_to_parent_comment', 'edges')
|
||||||
answers_count = reduce(add, [edge['node']['edge_threaded_comments']['count'] for edge in comment_edges], 0)
|
answers_count = sum([edge['node']['edge_threaded_comments']['count'] for edge in comment_edges])
|
||||||
threaded_comments_available = True
|
threaded_comments_available = True
|
||||||
except KeyError:
|
except KeyError:
|
||||||
comment_edges = self._field('edge_media_to_comment', 'edges')
|
comment_edges = self._field('edge_media_to_comment', 'edges')
|
||||||
|
Loading…
Reference in New Issue
Block a user