-
-
Notifications
You must be signed in to change notification settings - Fork 535
Added functionality for fetching user_mentions
#367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import warnings | ||||||||||||||||||||||||||
| from functools import partial | ||||||||||||||||||||||||||
| from typing import Any, AsyncGenerator, Literal | ||||||||||||||||||||||||||
| from typing import Any, AsyncGenerator, Literal, List | ||||||||||||||||||||||||||
| from urllib.parse import urlparse | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import filetype | ||||||||||||||||||||||||||
|
|
@@ -785,6 +785,45 @@ async def search_tweet( | |||||||||||||||||||||||||
| previous_cursor | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| async def get_user_mentions( | ||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||
| handle: str, | ||||||||||||||||||||||||||
| search_count: int = 20 | ||||||||||||||||||||||||||
| ) -> List[Tweet]: | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix return type annotation to match actual implementation. The method declares it returns -) -> List[Tweet]:
+) -> List[Tuple[str, Tweet]]:You'll also need to import -from typing import Any, AsyncGenerator, List, Literal
+from typing import Any, AsyncGenerator, List, Literal, Tuple📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
| Fetches user mentions via search method. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Parameters | ||||||||||||||||||||||||||
| ---------- | ||||||||||||||||||||||||||
| handle : :class:`str` | ||||||||||||||||||||||||||
| The target user handle (eg: 5mknc5, elonmusk). | ||||||||||||||||||||||||||
| search_count : :class:`int`, default=20 | ||||||||||||||||||||||||||
| The number of latest tweets to retrieve in each request. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Returns | ||||||||||||||||||||||||||
| ------- | ||||||||||||||||||||||||||
| List[:class:`Tweet`] | ||||||||||||||||||||||||||
| A list of `Tweet` results. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Examples | ||||||||||||||||||||||||||
| -------- | ||||||||||||||||||||||||||
| >>> mentions = await client.get_user_mentions('5mknc5', search_count=30) | ||||||||||||||||||||||||||
| >>> for mention in mentions: | ||||||||||||||||||||||||||
| ... print(mention) | ||||||||||||||||||||||||||
| <Tweet id="..."> | ||||||||||||||||||||||||||
| <Tweet id="..."> | ||||||||||||||||||||||||||
| ... | ||||||||||||||||||||||||||
| ... | ||||||||||||||||||||||||||
|
Comment on lines
+810
to
+816
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update documentation examples to match actual return format. The examples show the result as - >>> mentions = await client.get_user_mentions('5mknc5', search_count=30)
- >>> for mention in mentions:
- ... print(mention)
- <Tweet id="...">
- <Tweet id="...">
+ >>> mentions = await client.get_user_mentions('5mknc5', search_count=30)
+ >>> for tweet_id, tweet in mentions:
+ ... print(f"Tweet ID: {tweet_id}, Tweet: {tweet}")
+ Tweet ID: 123456789, Tweet: <Tweet id="123456789">
+ Tweet ID: 123456790, Tweet: <Tweet id="123456790">📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
| result = await self.search_tweet(f"@{handle}", "Latest", count=search_count) | ||||||||||||||||||||||||||
| mentions = [ | ||||||||||||||||||||||||||
| tweet for tweet in result | ||||||||||||||||||||||||||
| if f"@{handle.lower()}" in (tweet.full_text or tweet.text or "").strip().lower() | ||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||
| mentions.sort(key=lambda x: int(x.id)) | ||||||||||||||||||||||||||
| return mentions | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| async def search_user( | ||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||
| query: str, | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: The method returns a list of (tweet_id, tweet) tuples, not Tweet objects as the docstring and type hint suggest.
Please update the docstring and type hint to match the actual return type, or modify the method to return a List[Tweet] as documented.