Skip to content

Sunny0969/Trend-Aware-Post-Generator-for-Twitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🧠 Trend-Aware Post Generator for Twitter (X)

Author: Suneel Pirkash

📌 Overview

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.


⚙️ Features

✅ 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


🧾 Output

The script generates a .csv file named like:

Create and Activate a Virtual Environment

python -m venv venv venv\Scripts\activate # On Windows

Install Dependencies

pip install -r requirements.txt pip install tweepy pandas openai nltk

Download NLTK Stopwords

nltk.download('stopwords')

🔐 API Keys Required

🐦 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/

🚀 How to Run

python collect_tweets.py

Console output like

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'

Notes on Rate Limiting

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 Formula

engagement_score = likes * 1 + retweets * 2 + replies * 3

File Structure

├── collect_tweets.py # Main script ├── ai_trend_aware_posts_*.csv # Output files ├── README.md # This file └── venv/ # Virtual environment (optional)

👥 AI Companies Analyzed

@OpenAI @AnthropicAI @GoogleDeepMind @MistralAI @xAI

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages