Merge pull request #115 from Minecon724/main

add likes operation
Этот коммит содержится в:
vladkens 2024-02-10 13:19:53 +02:00 коммит произвёл GitHub
родитель 32f83ab1cd 08ce488c57
Коммит 5c5e1d3fa8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 21 добавлений и 0 удалений

Просмотреть файл

@ -17,6 +17,7 @@ OP_Favoriters = "E-ZTxvWWIkmOKwYdNTEefg/Favoriters"
OP_UserTweets = "V1ze5q3ijDS1VeLwLY0m7g/UserTweets"
OP_UserTweetsAndReplies = "16nOjYqEdV04vN6-rgg8KA/UserTweetsAndReplies"
OP_ListLatestTweetsTimeline = "whF0_KH1fCkdLLoyNPMoEw/ListLatestTweetsTimeline"
OP_Likes = "IohM3gxQHfvWePH5E3KuNA/Likes"
GQL_URL = "https://twitter.com/i/api/graphql"
@ -305,3 +306,22 @@ class API:
async for rep in self.list_timeline_raw(list_id, limit=limit, kv=kv):
for x in parse_tweets(rep, limit):
yield x
# likes
async def likes_raw(self, uid: int, limit=-1, kv=None):
op = OP_Likes
kv = {
"userId": str(uid),
"count": 40,
"includePromotedContent": True,
"withVoice": True,
"withV2Timeline": True,
**(kv or {}),
}
async for x in self._gql_items(op, kv, limit=limit):
yield x
async def likes(self, uid: int, limit=-1, kv=None):
async for rep in self.likes_raw(uid, limit=limit, kv=kv):
for x in parse_tweets(rep.json(), limit):
yield x

Просмотреть файл

@ -192,6 +192,7 @@ def run():
c_lim("user_tweets", "Get user tweets", "user_id", "User ID", int)
c_lim("user_tweets_and_replies", "Get user tweets and replies", "user_id", "User ID", int)
c_lim("list_timeline", "Get tweets from list", "list_id", "List ID", int)
c_lim("likes", "Get user's liked tweets", "user_id", "User ID", int)
args = p.parse_args()
if args.command is None: