Conversation
Co-authored-by: dragon123xyz1 <dragon123xyz1@gmail.com>
|
Cursor Agent can help with this pull request. Just |
| print("no recipients") | ||
| return | ||
| hours = int(os.getenv("ACTIVE_HOURS", "24")) | ||
| max_results = int(os.getenv("MAX_RESULTS", "10")) |
There was a problem hiding this comment.
🟡 Missing validation for MAX_RESULTS causes silent API failures
The Twitter API's get_users_tweets endpoint requires max_results to be between 5 and 100. The code reads this value from environment variable without validation.
Click to expand
How it happens
At test.py:124, the code reads MAX_RESULTS from environment:
max_results = int(os.getenv("MAX_RESULTS", "10"))If a user sets MAX_RESULTS to a value less than 5 (e.g., MAX_RESULTS=3), the Twitter API will reject the request. The error is caught by the TweepyException handler at test.py:66-72, which returns {"tweets": [], "error": str(e)}.
At test.py:131, the code checks if data.get("tweets"): which is falsy for empty lists, so no users are included in items.
Impact
The email will be sent saying "无活跃AI大佬更新" (no active AI experts update) when in fact all API calls failed. Users receive a misleading email with no indication of the underlying error.
Recommendation: Add validation to ensure max_results is between 5 and 100: max_results = max(5, min(100, int(os.getenv("MAX_RESULTS", "10"))))
Was this helpful? React with 👍 or 👎 to provide feedback.
Implement a daily X information flow to collect and email recent tweets from active AI leaders.