Added likes_count to PostCommentAnswer tuple (#379)
This commit is contained in:
parent
0aa1ec7c76
commit
af4dbc00d7
instaloader
@ -255,7 +255,8 @@ class Instaloader:
|
|||||||
return {'id': comment.id,
|
return {'id': comment.id,
|
||||||
'created_at': int(comment.created_at_utc.replace(tzinfo=timezone.utc).timestamp()),
|
'created_at': int(comment.created_at_utc.replace(tzinfo=timezone.utc).timestamp()),
|
||||||
'text': comment.text,
|
'text': comment.text,
|
||||||
'owner': comment.owner._asdict()}
|
'owner': comment.owner._asdict(),
|
||||||
|
'likes_count': comment.likes_count}
|
||||||
|
|
||||||
def _postcomment_asdict(comment):
|
def _postcomment_asdict(comment):
|
||||||
return {**_postcommentanswer_asdict(comment),
|
return {**_postcommentanswer_asdict(comment),
|
||||||
@ -272,11 +273,13 @@ class Instaloader:
|
|||||||
for x, y in zip(comments_list[:-1], comments_list[1:]):
|
for x, y in zip(comments_list[:-1], comments_list[1:]):
|
||||||
if x['id'] != y['id']:
|
if x['id'] != y['id']:
|
||||||
unique_comments_list.append(y)
|
unique_comments_list.append(y)
|
||||||
elif combine_answers:
|
else:
|
||||||
combined_answers = unique_comments_list[-1].get('answers') or list()
|
unique_comments_list[-1]['likes_count'] = y.get('likes_count')
|
||||||
if 'answers' in y:
|
if combine_answers:
|
||||||
combined_answers.extend(y['answers'])
|
combined_answers = unique_comments_list[-1].get('answers') or list()
|
||||||
unique_comments_list[-1]['answers'] = get_unique_comments(combined_answers)
|
if 'answers' in y:
|
||||||
|
combined_answers.extend(y['answers'])
|
||||||
|
unique_comments_list[-1]['answers'] = get_unique_comments(combined_answers)
|
||||||
return unique_comments_list
|
return unique_comments_list
|
||||||
filename += '_comments.json'
|
filename += '_comments.json'
|
||||||
try:
|
try:
|
||||||
|
@ -17,11 +17,12 @@ PostSidecarNode.is_video.__doc__ = "Whether this node is a video."
|
|||||||
PostSidecarNode.display_url.__doc__ = "URL of image or video thumbnail."
|
PostSidecarNode.display_url.__doc__ = "URL of image or video thumbnail."
|
||||||
PostSidecarNode.video_url.__doc__ = "URL of video or None."
|
PostSidecarNode.video_url.__doc__ = "URL of video or None."
|
||||||
|
|
||||||
PostCommentAnswer = namedtuple('PostCommentAnswer', ['id', 'created_at_utc', 'text', 'owner'])
|
PostCommentAnswer = namedtuple('PostCommentAnswer', ['id', 'created_at_utc', 'text', 'owner', 'likes_count'])
|
||||||
PostCommentAnswer.id.__doc__ = "ID number of comment."
|
PostCommentAnswer.id.__doc__ = "ID number of comment."
|
||||||
PostCommentAnswer.created_at_utc.__doc__ = ":class:`~datetime.datetime` when comment was created (UTC)."
|
PostCommentAnswer.created_at_utc.__doc__ = ":class:`~datetime.datetime` when comment was created (UTC)."
|
||||||
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."
|
||||||
|
PostCommentAnswer.likes_count.__doc__ = "Number of likes on comment."
|
||||||
|
|
||||||
PostComment = namedtuple('PostComment', (*PostCommentAnswer._fields, 'answers')) # type: ignore
|
PostComment = namedtuple('PostComment', (*PostCommentAnswer._fields, 'answers')) # type: ignore
|
||||||
for field in PostCommentAnswer._fields:
|
for field in PostCommentAnswer._fields:
|
||||||
@ -340,7 +341,8 @@ class Post:
|
|||||||
return PostCommentAnswer(id=int(node['id']),
|
return PostCommentAnswer(id=int(node['id']),
|
||||||
created_at_utc=datetime.utcfromtimestamp(node['created_at']),
|
created_at_utc=datetime.utcfromtimestamp(node['created_at']),
|
||||||
text=node['text'],
|
text=node['text'],
|
||||||
owner=Profile(self._context, node['owner']))
|
owner=Profile(self._context, node['owner']),
|
||||||
|
likes_count=node['edge_liked_by']['count'])
|
||||||
|
|
||||||
def _postcommentanswers(node):
|
def _postcommentanswers(node):
|
||||||
if 'edge_threaded_comments' not in node:
|
if 'edge_threaded_comments' not in node:
|
||||||
|
Loading…
Reference in New Issue
Block a user