-
-
Notifications
You must be signed in to change notification settings - Fork 560
feat: “About this account” support to fetch account-based-in location from X #398
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import asyncio | ||
| from twikit.guest import Client | ||
|
|
||
|
|
||
| AUTH_INFO_1 = '...' | ||
| AUTH_INFO_2 = '...' | ||
| PASSWORD = '...' | ||
|
|
||
| client = Client('en-US') | ||
|
|
||
|
|
||
| async def main(): | ||
| client.load_cookies('cookies.json') | ||
| client_user = await client.user() | ||
|
|
||
| about = await client.get_user_about('sama') | ||
| print(about) | ||
| print(f'Based in: {about.account_based_in}') | ||
| print(f'Username changes: {about.username_changes}') | ||
| print(f'Identity verified: {about.is_identity_verified}') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| asyncio.run(main()) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,7 @@ | |
| from ..trend import Location, PlaceTrend, PlaceTrends, Trend | ||
| from ..tweet import CommunityNote, Poll, ScheduledTweet, Tweet, tweet_from_data | ||
| from ..ui_metrics import solve_ui_metrics | ||
| from ..user import User | ||
| from ..user import AccountAbout, User | ||
| from ..utils import ( | ||
| Flow, | ||
| Result, | ||
|
|
@@ -1401,6 +1401,29 @@ async def get_user_by_screen_name(self, screen_name: str) -> User: | |
|
|
||
| return User(self, user_data) | ||
|
|
||
| async def get_user_about(self, screen_name: str) -> AccountAbout: | ||
| """ | ||
| Fetches "About this account" information by screen name. | ||
|
|
||
| Parameter | ||
| --------- | ||
| screen_name : :class:`str` | ||
| The screen name of the Twitter user. | ||
|
|
||
| Returns | ||
| ------- | ||
| :class:`AccountAbout` | ||
| A data object containing profile provenance details. | ||
| """ | ||
| response, _ = await self.gql.about_account(screen_name) | ||
| user_result = response.get('data', {}).get('user_result_by_screen_name') | ||
| if not user_result or 'result' not in user_result: | ||
| raise UserNotFound('The user does not exist.') | ||
| user_data = user_result['result'] | ||
| if user_data.get('__typename') == 'UserUnavailable': | ||
| raise UserUnavailable(user_data.get('message')) | ||
| return AccountAbout(user_data) | ||
|
|
||
|
Comment on lines
+1404
to
+1426
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. 🧩 Analysis chainScript executed: #!/bin/bash
# First, find the client.py file and verify basic structure
fd -t f "client.py" | head -5Repository: d60/twikit <shell_result> twikit AccountAbout class documentation <web_search_result> twikit Python SDK AccountAbout class gql about_account <web_search_result>
Tell me which and I’ll fetch the exact docs/code. twikit Python SDK AccountAbout class source code and gql about_account GraphQL query method documentation <web_search_result>
With that I can fetch the exact source and the gql about_account documentation. Based on the context provided, I can see that Let me now assess the review comment on its merits: Evaluating the Original Review Comment: Given:
Conclusion: The review comment makes valid suggestions for documentation improvements. However, the verification requests (checking if gql.about_account and AccountAbout exist) cannot be completed without direct repository access. Since the code is already shown to be implemented and integrated, these concerns are likely addressed. The only verifiable issue is the docstring inconsistency ("Parameter" vs "Parameters"), which is a minor documentation fix. Correct the docstring typo and consider adding examples for consistency. The implementation is sound with proper error handling. One clear issue:
Consider also adding an Examples section if similar methods in the file use this pattern. The review's verification requests about 🧰 Tools🪛 Ruff (0.14.5)1421-1421: Avoid specifying long messages outside the exception class (TRY003) 🤖 Prompt for AI Agents |
||
| async def get_user_by_id(self, user_id: str) -> User: | ||
| """ | ||
| Fetches a user by ID | ||
|
|
||
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.
Remove unused variable.
The
client_uservariable is fetched but never used. Consider either removing this line or usingclient_user.screen_nameinstead of the hardcoded'sama'on line 16 to make the example more dynamic.Apply this diff to remove the unused line:
Or alternatively, use the fetched user:
🧰 Tools
🪛 Ruff (0.14.5)
14-14: Local variable
client_useris assigned to but never usedRemove assignment to unused variable
client_user(F841)
🤖 Prompt for AI Agents