From 08ce488c57adef0f089bfedb96e442da5f4562f2 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sun, 28 Jan 2024 17:21:21 +0100 Subject: [PATCH] likes --- twscrape/api.py | 20 ++++++++++++++++++++ twscrape/cli.py | 1 + 2 files changed, 21 insertions(+) diff --git a/twscrape/api.py b/twscrape/api.py index 5e94041..2d858cc 100644 --- a/twscrape/api.py +++ b/twscrape/api.py @@ -17,6 +17,7 @@ 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 @@ async def list_timeline(self, list_id: int, limit=-1, kv=None): 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 \ No newline at end of file diff --git a/twscrape/cli.py b/twscrape/cli.py index 083a8ef..21127f2 100644 --- a/twscrape/cli.py +++ b/twscrape/cli.py @@ -192,6 +192,7 @@ def c_lim(name: str, msg: str, a_name: str, a_msg: str, a_type: type = str): 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: