Skip to content

Commit

Permalink
Merge pull request #115 from Minecon724/main
Browse files Browse the repository at this point in the history
add likes operation
  • Loading branch information
vladkens authored Feb 10, 2024
2 parents 32f83ab + 08ce488 commit 5c5e1d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions twscrape/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions twscrape/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5c5e1d3

Please sign in to comment.