A Python tool to monitor your X (formerly Twitter) followers, track who unfollows you, and maintain a history of follower changes. Can be run locally or automated using GitHub Actions.
git clone https://github.com/prathamdby/x-followers-monitor.git
cd x-followers-monitorpython -m venv venv
# On Windows:
.\venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activatepip install -r requirements.txt
playwright install chromium
playwright install-deps chromium- Install the Cookie-Editor browser extension.
- Log into X (Twitter) in your browser.
- Use Cookie-Editor to export cookies as JSON.
- Save them as
cookies.jsonin the project root OR set as an environment variable (see below).
- Required:
X_USERNAME: Your X (Twitter) username (without @)X_COOKIES: Paste your cookies JSON as a string (must be exported as JSON from Cookie-Editor)
- Optional:
DISCORD_WEBHOOK_URL: Your Discord webhook URL to receive follower updates
Example (Windows):
set X_USERNAME=your_username
set X_COOKIES={...your_cookies_json...}
set DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/your_webhook_urlExample (macOS/Linux):
export X_USERNAME=your_username
export X_COOKIES='{...your_cookies_json...}'
export DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/your_webhook_urlpython main.py- If you set the
DISCORD_WEBHOOK_URLenvironment variable, the script will post follower changes to your Discord channel after each run. - The webhook message includes new followers, unfollowers, and net change.
- You can create a webhook in your Discord server settings (Server Settings > Integrations > Webhooks > New Webhook).
- Go to your repository's Settings > Secrets and Variables > Actions.
- Add the following secrets (all required except webhook):
X_COOKIES: Your cookies JSON string (required)X_USERNAME: Your X username (required)DISCORD_WEBHOOK_URL(optional): Your Discord webhook URL
- The workflow will run automatically every 6 hours or can be triggered manually from the Actions tab.
followers_data.json: Current snapshot of your followersfollowers_history/: Directory containing historical datalatest.json: Most recent follower datafollowers_YYYYMMDD_HHMMSS.json: Timestamped snapshots
- Never commit your
cookies.jsonfile or secrets to version control. - If you see login errors, refresh your cookies.
- If selectors break, X (Twitter) may have changed their frontend; update selectors in
main.py.
MIT