-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Update client.py #271
base: main
Are you sure you want to change the base?
Update client.py #271
Conversation
sometimes the tweet retrieved from X would be malformatted and doesn't have the key "core", this can due to multiple reasons like the the original retweeted user has deleted the account
Reviewer's Guide by SourceryThe PR adds error handling to the tweet parsing logic in the search_tweet function to handle malformed tweets where the "core" key is missing, which can happen when retweeted content is from deleted accounts. Sequence diagram for tweet parsing with error handlingsequenceDiagram
participant Client
participant Data
participant Tweet
Client->>Data: Retrieve tweet data
alt Tweet data is well-formed
Data->>Tweet: Pass data to tweet_from_data
Tweet-->>Client: Return tweet
Client->>Client: Append tweet to results
else Tweet data is malformed
Data->>Tweet: Pass data to tweet_from_data
Tweet-->>Client: Raise KeyError
Client->>Client: Set tweet to None
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
WalkthroughThe changes made in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Hey @AlanWoo77 - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding logging in the except block to track when tweets fail to parse due to missing keys. This will help with monitoring and debugging these issues.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
twikit/client/client.py (2)
738-742
: LGTM! Consider adding debug logging.The added error handling for KeyError exceptions is a good defensive programming practice that aligns with the PR objectives to handle malformatted tweets. This prevents the method from crashing when encountering tweets with missing "core" data.
Consider adding debug logging to help track these occurrences:
try: tweet = tweet_from_data(self, item) except KeyError: + logging.debug(f"Skipping malformed tweet due to missing key: {item}") tweet = None
738-742
: Consider applying consistent error handling across similar methods.The added error handling for malformed tweets is currently only implemented in
search_tweet
. Similar methods that usetweet_from_data
could benefit from the same defensive approach.Consider applying similar error handling in other methods such as:
get_timeline
get_user_tweets
get_tweet_by_id
get_list_tweets
get_community_tweets
get_communities_timeline
search_community_tweet
This would ensure consistent behavior across the library when encountering malformed tweets.
sometimes the tweet retrieved from X would be malformatted and doesn't have the key "core", this can due to multiple reasons like the the original retweeted user has deleted the account
Summary by Sourcery
Bug Fixes:
Summary by CodeRabbit
Bug Fixes
New Features
Tweet
objects are returned in search results.