Turn your blog posts into engaging Twitter threads automatically! This AI-powered bot monitors your blog directory and instantly creates Twitter threads from new posts.
📖 Follow my blog: TheRanLBlog - Where I share my tech adventures and insights!
- ✨ Real-time Monitoring: Now watches your blog directory for new posts
- 🚀 Instant Processing: Automatically handles new markdown files as they arrive
- 🔄 Startup Processing: Picks up the latest post when you start the bot
- ⚡ Smart Directory Handling: Better path management across operating systems
- 🛡️ Improved Error Handling: Better recovery from API and file system issues
- 🧠 AI-powered tweet generation using Google's Gemini
- 🧵 Automatically creates threaded tweets
- 📝 Processes markdown files from your blog
- ⏱️ Smart rate limiting and error handling
- 🔄 Supports dry run mode for testing
- 🎯 Optimized for engagement and readability
- 🔍 Real-time blog directory monitoring
- 🚀 Instant tweet generation for new posts
- 🔄 Processes latest post on startup
-
Clone the Repository
git clone <your-repo-url> cd twitter_bot
-
Set Up Python Environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Configure Your Credentials
- Copy
.env.exampleto.env
cp .env.example .env
-
Get your Twitter API credentials:
- Go to Twitter Developer Portal
- Create a new app or select existing one
- Enable OAuth 1.0a with Read & Write permissions
- Generate API Key, API Secret, Access Token, and Access Token Secret
-
Get your Gemini API key:
- Visit Google AI Studio
- Create a new API key
-
Update
.envwith your credentials:TWITTER_API_KEY=your_api_key TWITTER_API_SECRET=your_api_secret TWITTER_ACCESS_TOKEN=your_access_token TWITTER_ACCESS_TOKEN_SECRET=your_access_token_secret GEMINI_API_KEY=your_gemini_api_key BLOG_POSTS_PATH=/path/to/your/blog/posts ```
- Copy
🆕 New Directory Monitoring Feature The bot now actively monitors your blog directory:
The bot now monitors your blog directory for new markdown files:
python src/main.py- Processes the most recent post on startup
- Watches for new markdown files
- Automatically generates and posts tweets for new content
- Use Ctrl+C to stop monitoring
python src/main.py --dry-run- Same monitoring functionality
- Shows generated tweets without posting
- Perfect for testing your setup
python src/main.pyThis will generate and post the tweets.
-
Continuous Monitoring (New!)
- Watches your specified blog directory
- Detects new markdown files instantly
- Processes the latest post on startup
- Handles file system events reliably
-
Blog Post Processing
- Scans your specified directory for markdown files
- Extracts frontmatter metadata and content
- Supports Hugo-style blog posts
-
AI Tweet Generation
- Uses Gemini AI to analyze your blog content
- Generates engaging, conversational tweet threads
- Maintains natural flow while preserving key information
- Automatically includes relevant hashtags
-
Smart Twitter Posting
- Creates a main tweet followed by threaded replies
- Handles rate limiting intelligently
- Implements exponential backoff for reliability
- Provides detailed progress feedback
- Added real-time directory monitoring
- Added automatic processing of new files
- Added latest post processing on startup
- Improved cross-platform path handling
- Enhanced error recovery and logging
- Updated documentation with new features
- Initial release with basic tweet generation
- Manual blog post processing
- Thread creation capabilities
- Rate limit handling
Want to tweak how your tweets are generated? The bot is highly customizable:
- Tweet Style: Modify the prompt in
tweet_generator.py - Posting Behavior: Adjust delays and retry logic in
twitter_poster.py - Content Processing: Customize blog parsing in
blog_reader.py
- Run with
--dry-runfirst to review generated tweets - Keep your API keys secure and never commit them
- Monitor your Twitter API usage limits
- Regular updates to your blog directory path as needed
Found a bug or have an improvement in mind? Contributions are welcome!
- Fork the repository
- Create your feature branch
- Submit a pull request
This project is open source and available under the MIT License.
If you find this bot useful, don't forget to star the repository! It helps others discover this tool.
Built with ❤️ for bloggers who love automation