-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from niuware/development
Add 'Comments' endpoint
- Loading branch information
Showing
11 changed files
with
169 additions
and
46 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from .like_graph_ql import LikeGraphQL | ||
from .parser import Parser | ||
|
||
|
||
class Comments(LikeGraphQL): | ||
|
||
def __init__(self, instance): | ||
super().__init__(instance, "/web/comments/{action}/{id}/") | ||
|
||
def of_post(self, timeline_post): | ||
shortcode = getattr(timeline_post, "shortcode", None) | ||
if shortcode is None: | ||
return [] | ||
variables = { | ||
"shortcode": shortcode, | ||
"first": self.DEFAULT_EDGE_COUNT | ||
} | ||
return self._loop("97b41c52301f77ce508f55e66d17620e", | ||
variables=variables, | ||
page_info_parser="edge_media_to_parent_comment", | ||
page_info_parser_path="shortcode_media", | ||
data_parser=Parser.parent_comments) | ||
|
||
def of_comment(self, comment): | ||
comment_id = getattr(comment, "id", None) | ||
if comment_id is None: | ||
return [] | ||
variables = { | ||
"comment_id": comment_id, | ||
"first": 6 | ||
} | ||
return self._loop("51fdd02b67508306ad4484ff574a0b62", | ||
variables=variables, | ||
page_info_parser="edge_threaded_comments", | ||
page_info_parser_path="comment", | ||
data_parser=Parser.threaded_comments) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from .base_graph_ql import BaseGraphQL | ||
|
||
|
||
class LikeGraphQL(BaseGraphQL): | ||
|
||
def __init__(self, instance, url): | ||
self._url = url | ||
super().__init__(instance) | ||
|
||
def _toggle_like(self, obj, action): | ||
endpoint = 'like' if action == 'like' else 'unlike' | ||
obj_id = getattr(obj, "id", None) | ||
if obj_id is None: | ||
return False | ||
response = self.post(self._url.format(action=endpoint, id=obj_id), | ||
use_auth=True, | ||
headers={ | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
}) | ||
if response and response.get("status") == "ok": | ||
return True | ||
return False | ||
|
||
def unlike(self, obj): | ||
return self._toggle_like(obj, 'unlike') | ||
|
||
def like(self, obj): | ||
return self._toggle_like(obj, 'like') |
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
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
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
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