A Twitter bot that automatically tweets out Los Angeles Chargers news from various RSS feeds.
- π° Fetches news from multiple RSS sources (ESPN, NFL.com, The Athletic)
- π€ Automatically posts new Chargers-related articles to Twitter
- π« Prevents duplicate posts by tracking previously posted articles
- β° Runs on a schedule (configurable interval)
- π Filters articles by Chargers-related keywords
- π€ AI-Powered Threads: Generates detailed tweet threads about past heartbreaking Chargers losses using AI (Groq, Gemini, or OpenAI)
- Python 3.8 or higher
- Twitter Developer Account with API access
- Internet connection
- AI Provider API Key (for AI-powered threads): Groq (free), Google Gemini (free), or OpenAI (paid)
- Go to Twitter Developer Portal
- Create a new app or use an existing one
- Navigate to "Keys and Tokens"
- Generate the following credentials:
- API Key and API Secret
- Access Token and Access Token Secret
- Bearer Token
pip install -r requirements.txt-
Copy the example environment file:
cp env.example .env
-
Edit
.envand add your Twitter API credentials:TWITTER_API_KEY=your_api_key_here TWITTER_API_SECRET=your_api_secret_here TWITTER_ACCESS_TOKEN=your_access_token_here TWITTER_ACCESS_TOKEN_SECRET=your_access_token_secret_here TWITTER_BEARER_TOKEN=your_bearer_token_here -
(Optional) Add AI Provider credentials for AI-powered threads:
# For Groq (FREE - Recommended) AI_PROVIDER=groq GROQ_API_KEY=your_groq_api_key_here # OR for Google Gemini (FREE) AI_PROVIDER=gemini GEMINI_API_KEY=your_gemini_api_key_here # OR for OpenAI (Paid) AI_PROVIDER=openai OPENAI_API_KEY=your_openai_api_key_hereSee FREE_AI_SETUP.md for detailed setup instructions.
python -c "from config import validate_config; validate_config(); print('Config valid!')"To fetch news and post once:
python bot.pyTo see what the bot would tweet without actually posting:
python bot.py --dry-runOr use the dry run script:
python dry_run.pyThis will:
- Find the most recent Chargers article from all sources
- Draft the tweet and display it
- Show article details (title, source, link, publish date)
- Display the full tweet text and character count
- Does NOT post to Twitter - perfect for testing!
To test the bot by tweeting the most recent Chargers article (regardless of age or if already posted):
python bot.py --testOr use the test script:
python test_tweet.pyThis will:
- Find the most recent Chargers article from all sources
- Tweet it immediately (bypasses age and duplicate checks)
- Does NOT save it to the posted articles list (won't interfere with normal bot operation)
Generate and post a detailed tweet thread about a past heartbreaking Chargers loss using AI:
Preview (Dry Run):
python bot.py --heartbreak-dry-runPost Live:
python bot.py --heartbreakThis feature:
- Uses AI to generate an 8-12 tweet thread telling the complete story of a game
- Includes context: teams, location, date, and what the game meant
- Fact-checks using Pro-Football-Reference.com for accuracy
- Tells the full story with key moments, scores, and turning points
- Posts as a proper Twitter thread (linked tweets)
Requirements:
- AI provider API key (Groq, Gemini, or OpenAI)
- See FREE_AI_SETUP.md for setup instructions
Schedule with GitHub Actions:
- Can be scheduled to run automatically (e.g., weekly)
- See GITHUB_ACTIONS_SETUP.md for setup
To run the bot continuously and check for news at regular intervals:
python scheduler.pyBy default, it checks every 6 hours. You can change this in your .env file by setting CHECK_INTERVAL_HOURS.
To run the scheduler in the background:
nohup python scheduler.py > bot.log 2>&1 &Or use a process manager like systemd or supervisord for production.
- News Fetching: The bot checks RSS feeds from configured news sources
- Filtering: Only articles containing Chargers-related keywords are kept
- Duplicate Prevention: Article URLs are tracked in
posted_articles.txtto avoid reposting - Tweet Formatting: Articles are formatted into tweets (max 280 characters) with title and link
- Posting: New articles are posted to Twitter with rate limiting protection
Edit config.py to add or modify news sources. Each source should have:
name: Display nameurl: RSS feed URLkeywords: List of keywords to filter Chargers-related articles
Edit .env to configure:
CHECK_INTERVAL_HOURS: How often to check for news (default: 6)DEBUG: Enable debug logging (default: False)
Edit .env to configure AI provider:
AI_PROVIDER: Choosegroq(default, free),gemini(free), oropenai(paid)GROQ_API_KEY: Your Groq API key (if using Groq)GROQ_MODEL: Model to use (default:groq/compound)GEMINI_API_KEY: Your Gemini API key (if using Gemini)GEMINI_MODEL: Model to use (default:gemini-pro)OPENAI_API_KEY: Your OpenAI API key (if using OpenAI)OPENAI_MODEL: Model to use (default:gpt-3.5-turbo)
See FREE_AI_SETUP.md for detailed AI provider setup.
chargers-bot/
βββ bot.py # Main bot logic (includes AI thread generation)
βββ scheduler.py # Scheduler for periodic runs
βββ dry_run.py # Dry run script to draft tweets without posting
βββ test_tweet.py # Test script to tweet most recent article
βββ test_bot.py # Test script to preview what would be posted
βββ config.py # Configuration settings
βββ requirements.txt # Python dependencies
βββ env.example # Example environment variables
βββ .env # Your actual credentials (not in git)
βββ .gitignore # Git ignore rules
βββ posted_articles.txt # Track posted articles (auto-generated)
βββ FREE_AI_SETUP.md # AI provider setup guide
βββ GITHUB_ACTIONS_SETUP.md # GitHub Actions deployment guide
βββ .github/
β βββ workflows/
β βββ heartbreak-thread.yml # GitHub Actions workflow for scheduled threads
βββ README.md # This file
- 401 Unauthorized: Check your API credentials in
.env - 403 Forbidden: Your app may not have write permissions. Check Twitter Developer Portal settings
- Rate Limits: The bot automatically handles rate limits with
wait_on_rate_limit=True
- Some RSS feeds may require authentication or have rate limits
- Check feed URLs in
config.pyare still valid - Enable
DEBUG=Truein.envto see detailed logs
- The bot tracks posted articles in
posted_articles.txt - If you want to reset, delete this file (but you'll risk reposting old articles)
- Model not found: Check that your API key is valid and you have access to the model
- Request too large: The prompt may be too long. Try a different model or reduce prompt size
- Inaccurate facts: The AI uses web search to fact-check, but may still have errors. Consider reviewing before posting
- API errors: Verify your API key is correct and has sufficient credits/quota
- See FREE_AI_SETUP.md for troubleshooting specific providers
Want to deploy this bot for free? Check out GitHub Actions - it's completely free and perfect for this bot!
- π― GitHub Actions (Recommended) - Completely free, runs on schedule
- π Railway - Free $5/month credit
- π PythonAnywhere - Free tier available
- βοΈ Render/Fly.io - Other free options
The easiest way is GitHub Actions - just push to GitHub and add your secrets!
- Set up AI provider for heartbreaking loss threads (see FREE_AI_SETUP.md)
- Deploy to GitHub Actions for scheduled threads (see GITHUB_ACTIONS_SETUP.md)
- Add more news sources
- Implement better article filtering
- Add retry logic for failed posts
- Set up monitoring/alerting
This project is open source and available for personal use.
Make sure to comply with Twitter's API Terms of Service and rate limits. Use responsibly!