Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MockedError(Exception):
"user_tweets_and_replies",
"list_timeline",
"trends",
"list_members",
]


Expand Down
18 changes: 18 additions & 0 deletions twscrape/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
OP_UserMedia = "vFPc2LVIu7so2uA_gHQAdg/UserMedia"
OP_Bookmarks = "-LGfdImKeQz0xS_jjUwzlA/Bookmarks"
OP_GenericTimelineById = "CT0YFEFf5GOYa5DJcxM91w/GenericTimelineById"
OP_ListMembers = "CDYIXKGINDLWntNdeXVUgQ"

GQL_URL = "https://x.com/i/api/graphql"
GQL_FEATURES = { # search values here (view source) https://x.com/
Expand Down Expand Up @@ -514,3 +515,20 @@ async def bookmarks(self, limit=-1, kv: KV = None):
async for rep in gen:
for x in parse_tweets(rep.json(), limit):
yield x

# list members of a List

async def list_members_raw(self, list_id: int, limit: int = -1, kv: KV = None):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func to get members from list

# Raw query for list members
op = OP_ListMembers
kv = {"listId": str(list_id), "count": 20, **(kv or {})}
async with aclosing(self._gql_items(op, kv, limit=limit)) as gen:
async for page in gen:
yield page

async def list_members(self, list_id: int, limit: int = -1, kv: KV = None):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

# Parse the list members from the raw query
async with aclosing(self.list_members_raw(list_id, limit=limit, kv=kv)) as gen:
async for page in gen:
for user in parse_users(page.json(), limit):
yield user
1 change: 1 addition & 0 deletions twscrape/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def c_lim(name: str, msg: str, a_name: str, a_msg: str, a_type: type = str):
c_lim("user_media", "Get user's media", "user_id", "User ID", int)
c_lim("list_timeline", "Get tweets from list", "list_id", "List ID", int)
c_lim("trends", "Get trends", "trend_id", "Trend ID or name", str)
c_lim("list_members", "Get List members by list ID", "list_id", "List ID", int)

args = p.parse_args()
if args.command is None:
Expand Down