From 5989e37c762f00bd2aaef1d3570cb7cf784d95d8 Mon Sep 17 00:00:00 2001 From: "Mikhail Andreev (adw0rd)" Date: Thu, 2 Dec 2021 08:29:23 +0100 Subject: [PATCH] No "response_to_comment" method [#365] Added replied_to_comment_id for cl.media_comment --- docs/usage-guide/comment.md | 29 ++++++++++++++++++++++------- instagrapi/mixins/comment.py | 25 +++++++++++++------------ setup.py | 2 +- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/docs/usage-guide/comment.md b/docs/usage-guide/comment.md index 71162f68..c08b52ad 100644 --- a/docs/usage-guide/comment.md +++ b/docs/usage-guide/comment.md @@ -2,13 +2,13 @@ Post comment, viewing, like and unlike comments -| Method | Return | Description -| ---------------------------------------------------------- | ------------------ | -------------------------- -| media_comment(media_id: str, message: str) | Comment | Add new comment to media -| media_comments(media_id: str, amount: int = 0) | List\[Comment] | Get a list comments for media (amount=0 - fetch all comments) -| comment_like(comment_pk: int) | bool | Like a comment -| comment_unlike(comment_pk: int) | bool | Unlike a comment -| comment_bulk_delete(media_id: str, comment_pks: List[int]) | bool | Delete a comment +| Method | Return | Description +| --------------------------------------------------------------------------------------- | ------------------ | -------------------------- +| media_comment(media_id: str, message: str, replied_to_comment_id: Optional[int] = None) | Comment | Add new comment to media +| media_comments(media_id: str, amount: int = 0) | List\[Comment] | Get a list comments for media (amount=0 - all comments) +| comment_like(comment_pk: int) | bool | Like a comment +| comment_unlike(comment_pk: int) | bool | Unlike a comment +| comment_bulk_delete(media_id: str, comment_pks: List[int]) | bool | Delete a comment Example: @@ -36,6 +36,21 @@ Example: 'has_liked': None, 'like_count': None} +>>> comment = cl.media_comment(media_id, "Test comment 2", replied_to_comment_id=comment.pk) +>>> comment.dict() +{'pk': 17926777897585109, + 'text': 'Test comment 2', + 'user': {'pk': 1903424587, + 'username': 'adw0rd', + 'full_name': 'Mikhail Andreev', + 'profile_pic_url': HttpUrl('https://scontent-hel3-1.cdninstagram.com/v/t51.2885-19/s150x150/156689363_269505058076642_6448820957073669709_n.jpg?tp=1&_nc_ht=scontent-hel3-1.cdninstagram.com&_nc_ohc=EtzrL0pAdg8AX9pE_wN&edm=ABQSlwABAAAA&ccb=7-4&oh=e04d45b7651140e7fef61b1f67f1f408&oe=60C65AD1&_nc_sid=b2b2bd', scheme='https', host='scontent-hel3-1.cdninstagram.com', tld='com', host_type='domain', path='/v/t51.2885-19/s150x150/156689363_269505058076642_6448820957073669709_n.jpg', query='tp=1&_nc_ht=scontent-hel3-1.cdninstagram.com&_nc_ohc=EtzrL0pAdg8AX9pE_wN&edm=ABQSlwABAAAA&ccb=7-4&oh=e04d45b7651140e7fef61b1f67f1f408&oe=60C65AD1&_nc_sid=b2b2bd'), + 'stories': []}, + 'created_at_utc': datetime.datetime(2021, 5, 15, 14, 50, 3, tzinfo=datetime.timezone.utc), + 'content_type': 'comment', + 'status': 'Active', + 'has_liked': None, + 'like_count': None} + >>> comments = cl.media_comments(media_id) >>> comments[0].dict() {'pk': 17926777897585108, diff --git a/instagrapi/mixins/comment.py b/instagrapi/mixins/comment.py index 79a00469..fd7ab454 100644 --- a/instagrapi/mixins/comment.py +++ b/instagrapi/mixins/comment.py @@ -1,5 +1,5 @@ import random -from typing import List +from typing import List, Optional from instagrapi.exceptions import ClientError, ClientNotFoundError, MediaNotFound from instagrapi.extractors import extract_comment @@ -65,7 +65,7 @@ def get_comments(): comments = comments[:amount] return comments - def media_comment(self, media_id: str, text: str) -> Comment: + def media_comment(self, media_id: str, text: str, replied_to_comment_id: Optional[int] = None) -> Comment: """ Post a comment on a media @@ -83,18 +83,19 @@ def media_comment(self, media_id: str, text: str) -> Comment: """ assert self.user_id, "Login required" media_id = self.media_id(media_id) + data = { + "delivery_class": "organic", + "feed_position": "0", + "container_module": "self_comments_v2_feed_contextual_self_profile", # "comments_v2", + "user_breadcrumb": self.gen_user_breadcrumb(len(text)), + "idempotence_token": self.generate_uuid(), + "comment_text": text, + } + if replied_to_comment_id: + data["replied_to_comment_id"] = int(replied_to_comment_id) result = self.private_request( f"media/{media_id}/comment/", - self.with_action_data( - { - "delivery_class": "organic", - "feed_position": "0", - "container_module": "self_comments_v2_feed_contextual_self_profile", # "comments_v2", - "user_breadcrumb": self.gen_user_breadcrumb(len(text)), - "idempotence_token": self.generate_uuid(), - "comment_text": text, - } - ), + self.with_action_data(data), ) return extract_comment(result["comment"]) diff --git a/setup.py b/setup.py index 26153fee..953acf4d 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ setup( name='instagrapi', - version='1.15.19', + version='1.15.20', author='Mikhail Andreev', author_email='x11org@gmail.com', license='MIT',