feat: add search and likes commands
- Add 'twitter search' command with --type (Top/Latest/Photos/Videos), --max, --json, --filter - Add 'twitter likes' command to view tweets liked by a user - Add SearchTimeline and Likes GraphQL operations with fallback queryIds - Update README with new command examples (EN + CN)
This commit is contained in:
@@ -28,6 +28,8 @@ FALLBACK_QUERY_IDS = {
|
||||
"Bookmarks": "VFdMm9iVZxlU6hD86gfW_A",
|
||||
"UserByScreenName": "1VOOyvKkiI3FMmkeDNxM9A",
|
||||
"UserTweets": "E3opETHurmVJflFsUBVuUQ",
|
||||
"SearchTimeline": "VhUd6vHVmLBcw0uX-6jMLA",
|
||||
"Likes": "lIDpu_NWL7_VhimGGt0o6A",
|
||||
}
|
||||
|
||||
TWITTER_OPENAPI_URL = (
|
||||
@@ -312,6 +314,44 @@ class TwitterClient:
|
||||
},
|
||||
)
|
||||
|
||||
def fetch_user_likes(self, user_id, count=20):
|
||||
# type: (str, int) -> List[Tweet]
|
||||
"""Fetch tweets liked by a user."""
|
||||
return self._fetch_timeline(
|
||||
"Likes",
|
||||
count,
|
||||
lambda data: _deep_get(data, "data", "user", "result", "timeline_v2", "timeline", "instructions"),
|
||||
extra_variables={
|
||||
"userId": user_id,
|
||||
"includePromotedContent": False,
|
||||
"withClientEventToken": False,
|
||||
"withBirdwatchNotes": False,
|
||||
"withVoice": True,
|
||||
},
|
||||
)
|
||||
|
||||
def fetch_search(self, query, count=20, product="Top"):
|
||||
# type: (str, int, str) -> List[Tweet]
|
||||
"""Search tweets by query.
|
||||
|
||||
Args:
|
||||
query: Search query string.
|
||||
count: Max number of tweets to return.
|
||||
product: Search tab — "Top", "Latest", "People", "Photos", "Videos".
|
||||
"""
|
||||
return self._fetch_timeline(
|
||||
"SearchTimeline",
|
||||
count,
|
||||
lambda data: _deep_get(
|
||||
data, "data", "search_by_raw_query", "search_timeline", "timeline", "instructions",
|
||||
),
|
||||
extra_variables={
|
||||
"rawQuery": query,
|
||||
"querySource": "typed_query",
|
||||
"product": product,
|
||||
},
|
||||
)
|
||||
|
||||
def _fetch_timeline(self, operation_name, count, get_instructions, extra_variables=None):
|
||||
# type: (str, int, Callable[[Any], Any], Optional[Dict[str, Any]]) -> List[Tweet]
|
||||
"""Generic timeline fetcher with pagination and deduplication."""
|
||||
|
||||
Reference in New Issue
Block a user