This project fetches the latest tweets from leading AI companies, analyzes them for trends and engagement, and then generates new AI-related tweet ideas using OpenAI's GPT-3.5 model.
✅ Fetches recent tweets from top AI company handles
✅ Calculates engagement scores using likes, retweets, and replies
✅ Analyzes top-performing tweets to extract popular keywords
✅ Uses OpenAI GPT-3.5 to generate original, trend-aware tweet ideas
✅ Saves results to a structured .csv file with all key data
The script generates a .csv file named like:
python -m venv venv venv\Scripts\activate # On Windows
pip install -r requirements.txt pip install tweepy pandas openai nltk
nltk.download('stopwords')
🐦 Twitter API v2 Access (Free Tier)
BEARER_TOKEN = "your_token_here"
API_KEY = "your_key"
API_SECRET = "your_secret"
ACCESS_TOKEN = "your_access_token"
ACCESS_TOKEN_SECRET = "your_access_secret"
OPENAI_API_KEY = "your_openai_key"
Create an app at: https://developer.twitter.com/
python collect_tweets.py
Connecting to Twitter API...
Fetching tweets...
Fetched 10 tweets from @OpenAI
Fetched 10 tweets from @AnthropicAI
Extracting keywords...
Generating new posts using OpenAI...
Saving CSV...
✅ Done! Saved to 'ai_trend_aware_posts_20250623_1547.csv'
Twitter's Free API has strict rate limits. If you fetch tweets from too many users too quickly, you may see:
Rate limit hit for @handle. Waiting 15 mins...
engagement_score = likes * 1 + retweets * 2 + replies * 3
├── collect_tweets.py # Main script ├── ai_trend_aware_posts_*.csv # Output files ├── README.md # This file └── venv/ # Virtual environment (optional)
@OpenAI @AnthropicAI @GoogleDeepMind @MistralAI @xAI