{"id":29061729,"url":"https://github.com/monarch1108/twitter_bot","last_synced_at":"2025-06-27T08:09:04.383Z","repository":{"id":299471593,"uuid":"1003152570","full_name":"MONARCH1108/Twitter_Bot","owner":"MONARCH1108","description":"An intelligent Twitter automation system that crawls BBC news, generates engaging tweets using AI, and automatically posts them to Twitter/X. ","archived":false,"fork":false,"pushed_at":"2025-06-16T18:02:08.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-16T19:20:29.640Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MONARCH1108.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-16T17:50:28.000Z","updated_at":"2025-06-16T18:02:12.000Z","dependencies_parsed_at":"2025-06-16T19:20:31.853Z","dependency_job_id":"e3083d39-f765-4706-8341-890ec5dad2ed","html_url":"https://github.com/MONARCH1108/Twitter_Bot","commit_stats":null,"previous_names":["monarch1108/twitter_bot"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MONARCH1108/Twitter_Bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MONARCH1108%2FTwitter_Bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MONARCH1108%2FTwitter_Bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MONARCH1108%2FTwitter_Bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MONARCH1108%2FTwitter_Bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MONARCH1108","download_url":"https://codeload.github.com/MONARCH1108/Twitter_Bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MONARCH1108%2FTwitter_Bot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262219794,"owners_count":23276888,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-27T08:05:43.930Z","updated_at":"2025-06-27T08:09:04.365Z","avatar_url":"https://github.com/MONARCH1108.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🤖 Twitter News Bot\n\nAn intelligent Twitter automation system that crawls BBC news, generates engaging tweets using AI, and automatically posts them to Twitter/X. This project combines web scraping, natural language processing, and social media automation into a comprehensive news-to-tweet pipeline.\n\n## 🌟 Features\n\n- **📰 Smart News Crawling**: Automated BBC news article discovery and extraction\n- **🧠 AI-Powered Content Generation**: Uses Ollama (Llama 3.2) for tweet creation and Google Gemini for hashtag generation\n- **🎯 Intelligent Tweet Optimization**: Sentiment analysis, urgency detection, and topic extraction\n- **🔄 Automated Social Media Posting**: Selenium-based Twitter/X posting with multiple fallback methods\n- **📊 Analytics \u0026 Insights**: Comprehensive data collection and analysis\n- **⚡ Parallel Processing**: Multi-threaded crawling and processing for efficiency\n- **🛡️ Robust Error Handling**: Multiple retry mechanisms and failsafes\n\n## 🏗️ Project Structure\n\n```\ntwitter-news-bot/\n├── bbc_crawler.py          # BBC news crawler with AI analysis\n├── tweet_generator.py      # AI-powered tweet and hashtag generation\n├── twitter_bot.py          # Automated Twitter posting bot\n├── requirements.txt        # Python dependencies\n├── README.md              # This file\n└── output/\n    ├── bbc_improved_data.json    # Crawled news data\n    ├── generated_tweets.json     # Generated tweets with hashtags\n    └── twitter_bot.log          # Bot execution logs\n```\n\n## 🚀 Quick Start\n\n### Prerequisites\n\n1. **Python 3.8+**\n2. **Ollama** with Llama 3.2 model\n3. **Google Gemini API Key**\n4. **Chrome Browser** and ChromeDriver\n5. **Twitter/X Account**\n\n### Installation\n\n1. **Clone the repository**\n   ```bash\n   https://github.com/MONARCH1108/Twitter_Bot.git\n   cd twitter-news-bot\n   ```\n\n2. **Install Python dependencies**\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n3. **Install and setup Ollama**\n   ```bash\n   # Install Ollama (visit https://ollama.ai for installation instructions)\n   ollama pull llama3.2:latest\n   ollama serve\n   ```\n\n4. **Install ChromeDriver**\n   - Download from [ChromeDriver](https://chromedriver.chromium.org/)\n   - Add to your system PATH or place in project directory\n\n### Configuration\n\n1. **Update `tweet_generator.py`**\n   ```python\n   GEMINI_API_KEY = \"your_gemini_api_key_here\"\n   JSON_FILE_PATH = \"path/to/bbc_improved_data.json\"\n   ```\n\n2. **Update `twitter_bot.py`**\n   ```python\n   TWITTER_USERNAME = \"your_twitter_username\"\n   TWITTER_PASSWORD = \"your_twitter_password\"\n   JSON_FILE_PATH = \"path/to/generated_tweets.json\"\n   ```\n\n## 📖 Usage\n\n### Step 1: Crawl BBC News\n```bash\npython bbc_crawler.py\n```\nThis will:\n- Discover and crawl BBC news articles\n- Extract content and analyze with AI\n- Save results to `bbc_improved_data.json`\n\n### Step 2: Generate Tweets\n```bash\npython tweet_generator.py\n```\nThis will:\n- Load crawled news data\n- Generate engaging tweets using Ollama\n- Create trending hashtags using Gemini\n- Save results to `generated_tweets.json`\n\n### Step 3: Post to Twitter\n```bash\npython twitter_bot.py\n```\nThis will:\n- Load generated tweets\n- Automatically post to Twitter/X\n- Handle rate limiting and errors\n- Log all activities\n\n### All-in-One Execution\n```bash\n# Run the complete pipeline\npython bbc_crawler.py \u0026\u0026 python tweet_generator.py \u0026\u0026 python twitter_bot.py\n```\n\n## ⚙️ Configuration Options\n\n### BBC Crawler (`bbc_crawler.py`)\n- **Model Selection**: Change Ollama model (default: `llama3.2:latest`)\n- **Categories**: Customize news categories to crawl\n- **Article Limits**: Set maximum articles per category\n- **Parallel Processing**: Adjust thread count for crawling\n\n### Tweet Generator (`tweet_generator.py`)\n- **API Keys**: Configure Gemini API access\n- **Content Filtering**: Set urgency and sentiment filters\n- **Tweet Length**: Customize tweet character limits\n- **Hashtag Count**: Control number of hashtags (3-5 recommended)\n\n### Twitter Bot (`twitter_bot.py`)\n- **Posting Intervals**: Time between tweets (minimum 10 seconds recommended)\n- **Browser Mode**: Headless vs. visible browser\n- **Retry Logic**: Configure retry attempts and timeouts\n- **Content Limits**: Maximum tweets per session\n\n## 📊 Output Examples\n\n### Generated Tweet Structure\n```json\n{\n  \"tweet\": \"Breaking: New climate change report reveals alarming trends in global temperatures. Scientists call for immediate action.\",\n  \"hashtags\": [\"#ClimateChange\", \"#BreakingNews\", \"#GlobalWarming\", \"#Science\", \"#Environment\"],\n  \"article_url\": \"https://www.bbc.com/news/science-environment-12345678\",\n  \"topics\": [\"climate change\", \"environment\", \"science\"],\n  \"tweet_with_hashtags\": \"Breaking: New climate change report reveals alarming trends... #ClimateChange #BreakingNews #GlobalWarming\"\n}\n```\n\n### Analytics Dashboard\n- **Total Articles Processed**: Real-time counting\n- **Sentiment Distribution**: Positive/Negative/Neutral breakdown\n- **Top Topics**: Most frequent news topics\n- **Success Rates**: Crawling and posting success metrics\n\n## 🔧 Advanced Features\n\n### Multi-Model AI Integration\n- **Ollama (Llama 3.2)**: Local tweet generation\n- **Google Gemini**: Cloud-based hashtag optimization\n- **BeautifulSoup**: Intelligent content extraction\n\n### Robust Error Handling\n- **Network Resilience**: Automatic retry with exponential backoff\n- **Content Validation**: Quality checks for articles and tweets\n- **Fallback Mechanisms**: Multiple posting strategies for Twitter\n\n### Performance Optimization\n- **Parallel Processing**: Concurrent article processing\n- **Smart Caching**: Avoid duplicate content\n- **Rate Limit Compliance**: Respect API and platform limits\n\n## 📋 Requirements\n\n### Python Dependencies\n```txt\nrequests\u003e=2.31.0\nbeautifulsoup4\u003e=4.12.0\nselenium\u003e=4.15.0\ngoogle-generativeai\u003e=0.3.0\nollama\u003e=0.1.0\naiohttp\u003e=3.9.0\nlxml\u003e=4.9.0\n```\n\n### System Requirements\n- **RAM**: 4GB minimum (8GB recommended for Ollama)\n- **Storage**: 2GB free space for models and data\n- **Network**: Stable internet connection\n- **OS**: Windows 10+, macOS 10.15+, or Linux\n\n## 🛡️ Safety \u0026 Ethics\n\n### Content Guidelines\n- **News Accuracy**: Only shares content from reputable BBC sources\n- **Fact Checking**: AI analysis includes sentiment and urgency validation\n- **Rate Limiting**: Respects Twitter's posting limits and guidelines\n\n### Privacy Protection\n- **No Personal Data**: Only processes public news content\n- **Secure Credentials**: Environment variable support for sensitive data\n- **GDPR Compliance**: No user data collection or storage\n\n### Terms of Service\n- **Twitter/X ToS**: Designed to comply with platform guidelines\n- **BBC Content**: Respects fair use and attribution policies\n- **API Usage**: Follows rate limits and usage policies\n\n## 🔧 Troubleshooting\n\n### Common Issues\n\n**1. Ollama Connection Failed**\n```bash\n# Check if Ollama is running\nollama list\nollama serve\n\n# Verify model installation\nollama pull llama3.2:latest\n```\n\n**2. Twitter Login Issues**\n- Verify credentials are correct\n- Check for 2FA requirements\n- Ensure account is not restricted\n\n**3. Gemini API Errors**\n- Verify API key is valid\n- Check quota and billing status\n- Ensure proper API permissions\n\n**4. ChromeDriver Issues**\n- Update Chrome browser\n- Download matching ChromeDriver version\n- Check PATH configuration\n\n### Debug Mode\nEnable detailed logging:\n```python\nlogging.basicConfig(level=logging.DEBUG)\n```\n\n## 🤝 Contributing\n\nWe welcome contributions! Please see our contributing guidelines:\n\n1. **Fork** the repository\n2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)\n3. **Commit** your changes (`git commit -m 'Add amazing feature'`)\n4. **Push** to the branch (`git push origin feature/amazing-feature`)\n5. **Open** a Pull Request\n\n### Development Setup\n```bash\n# Install development dependencies\npip install -r requirements-dev.txt\n\n# Run tests\npython -m pytest tests/\n\n# Format code\nblack *.py\nflake8 *.py\n```\n\n## 📜 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## ⚠️ Disclaimer\n\nThis tool is for educational and personal use only. Users are responsible for:\n- Complying with Twitter/X Terms of Service\n- Respecting content licensing and fair use\n- Following local laws and regulations\n- Using the tool ethically and responsibly\n\n## 🆘 Support\n\n- **Issues**: [GitHub Issues](https://github.com/yourusername/twitter-news-bot/issues)\n- **Discussions**: [GitHub Discussions](https://github.com/yourusername/twitter-news-bot/discussions)\n- **Documentation**: [Wiki](https://github.com/yourusername/twitter-news-bot/wiki)\n\n## 🚀 Roadmap\n\n### Version 2.0 (Planned)\n- [ ] **Multi-Platform Support**: LinkedIn, Facebook, Instagram\n- [ ] **Custom News Sources**: Beyond BBC integration\n- [ ] **Advanced AI Models**: GPT-4, Claude integration\n- [ ] **Web Dashboard**: Real-time monitoring interface\n- [ ] **Scheduled Posting**: Cron-like scheduling system\n- [ ] **Analytics Dashboard**: Engagement metrics and insights\n\n### Version 1.5 (In Progress)\n- [ ] **Docker Support**: Containerized deployment\n- [ ] **Cloud Deployment**: AWS/GCP integration\n- [ ] **Webhook Support**: Real-time news notifications\n- [ ] **Content Filtering**: Advanced topic and sentiment filters\n\n---\n\n**Made with ❤️ by [Your Name]**\n\n*Don't forget to ⭐ star this repository if you found it helpful!*","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonarch1108%2Ftwitter_bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonarch1108%2Ftwitter_bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonarch1108%2Ftwitter_bot/lists"}