feat: add hashtags
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from itd.users import get_user
|
from itd.users import get_user
|
||||||
from itd.comments import get_comments, add_comment, delete_comment, like_comment, unlike_comment, update_comment
|
from itd.comments import get_comments, add_comment, delete_comment, like_comment, unlike_comment, update_comment
|
||||||
|
from itd.hashtags import get_hastags, get_posts_by_hastag
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
def __init__(self, token: str):
|
def __init__(self, token: str):
|
||||||
@@ -12,20 +13,27 @@ class Client:
|
|||||||
return self.get_user('me')
|
return self.get_user('me')
|
||||||
|
|
||||||
|
|
||||||
def add_comment(self, post_id: int, content: str, reply_comment_id: int | None = None):
|
def add_comment(self, post_id: str, content: str, reply_comment_id: str | None = None):
|
||||||
return add_comment(self.token, post_id, content, reply_comment_id)
|
return add_comment(self.token, post_id, content, reply_comment_id)
|
||||||
|
|
||||||
def get_comments(self, post_id: int, limit: int = 20, cursor: int = 1, sort: str = 'popular'):
|
def get_comments(self, post_id: str, limit: int = 20, cursor: int = 0, sort: str = 'popular'):
|
||||||
return get_comments(self.token, post_id, limit, cursor, sort)
|
return get_comments(self.token, post_id, limit, cursor, sort)
|
||||||
|
|
||||||
def like_comment(self, id: int):
|
def like_comment(self, id: str):
|
||||||
return like_comment(self.token, id)
|
return like_comment(self.token, id)
|
||||||
|
|
||||||
def unlike_comment(self, id: int):
|
def unlike_comment(self, id: str):
|
||||||
return unlike_comment(self.token, id)
|
return unlike_comment(self.token, id)
|
||||||
|
|
||||||
def delete_comment(self, id: int):
|
def delete_comment(self, id: str):
|
||||||
return delete_comment(self.token, id)
|
return delete_comment(self.token, id)
|
||||||
|
|
||||||
def update_comment(self, id: int, content: str):
|
def update_comment(self, id: str, content: str):
|
||||||
return update_comment(self.token, id, content)
|
return update_comment(self.token, id, content)
|
||||||
|
|
||||||
|
|
||||||
|
def get_hastags(self, limit: int = 10):
|
||||||
|
return get_hastags(self.token, limit)
|
||||||
|
|
||||||
|
def get_posts_by_hashtag(self, hashtag: str, limit: int = 20, cursor: int = 0):
|
||||||
|
return get_posts_by_hastag(self.token, hashtag, limit, cursor)
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
from itd.request import fetch
|
from itd.request import fetch
|
||||||
|
|
||||||
def add_comment(token: str, post_id: int, content: str, reply_comment_id: int | None = None):
|
def add_comment(token: str, post_id: str, content: str, reply_comment_id: str | None = None):
|
||||||
data = {'content': content}
|
data = {'content': content}
|
||||||
if reply_comment_id:
|
if reply_comment_id:
|
||||||
data['replyTo'] = str(reply_comment_id)
|
data['replyTo'] = str(reply_comment_id)
|
||||||
return fetch(token, 'post', f'posts/{post_id}/comments', data)
|
return fetch(token, 'post', f'posts/{post_id}/comments', data)
|
||||||
|
|
||||||
def get_comments(token: str, post_id: int, limit: int = 20, cursor: int = 0, sort: str = 'popular'):
|
def get_comments(token: str, post_id: str, limit: int = 20, cursor: int = 0, sort: str = 'popular'):
|
||||||
return fetch(token, 'get', f'posts/{post_id}/comments', {'limit': limit, 'sort': sort, 'cursor': cursor})
|
return fetch(token, 'get', f'posts/{post_id}/comments', {'limit': limit, 'sort': sort, 'cursor': cursor})
|
||||||
|
|
||||||
def like_comment(token: str, comment_id: int):
|
def like_comment(token: str, comment_id: str):
|
||||||
return fetch(token, 'post', f'comments/{comment_id}/like')
|
return fetch(token, 'post', f'comments/{comment_id}/like')
|
||||||
|
|
||||||
def unlike_comment(token: str, comment_id: int):
|
def unlike_comment(token: str, comment_id: str):
|
||||||
return fetch(token, 'delete', f'comments/{comment_id}/like')
|
return fetch(token, 'delete', f'comments/{comment_id}/like')
|
||||||
|
|
||||||
def delete_comment(token: str, comment_id: int):
|
def delete_comment(token: str, comment_id: str):
|
||||||
return fetch(token, 'delete', f'comments/{comment_id}')
|
return fetch(token, 'delete', f'comments/{comment_id}')
|
||||||
|
|
||||||
def update_comment(token: str, comment_id: int, content: str):
|
def update_comment(token: str, comment_id: str, content: str):
|
||||||
return fetch(token, 'put', f'comments/{comment_id}', {'content': content})
|
return fetch(token, 'put', f'comments/{comment_id}', {'content': content})
|
||||||
7
itd/hashtags.py
Normal file
7
itd/hashtags.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from itd.request import fetch
|
||||||
|
|
||||||
|
def get_hastags(token: str, limit: int = 10):
|
||||||
|
return fetch(token, 'get', 'hashtags/trending', {'limit': limit})
|
||||||
|
|
||||||
|
def get_posts_by_hastag(token: str, hashtag: str, limit: int = 20, cursor: int = 0):
|
||||||
|
return fetch(token, 'get', f'hashtags/{hashtag}/posts', {'limit': limit, 'cursor': cursor})
|
||||||
Reference in New Issue
Block a user