Build an interactive ego network visualization of your Twitter mutuals with automatic clustering based on bio content.
- Fetches your Twitter followers and following using Twikit
- Identifies mutual connections
- Clusters mutuals by bio keywords using TF-IDF and K-Means
- Generates interactive HTML visualization with PyVis
- Color-coded clusters with hover tooltips
pip install -r requirements.txt# First run - will prompt for Twitter credentials
python main.py --username your_handle
# Subsequent runs use cached session
python main.py --username your_handle --clusters 8
# Auto-detect optimal number of clusters
python main.py --username your_handle --auto-clustersThe visualization is saved to output/ego_network.html. Open it in your browser to explore your mutual network!
If you see a "403 Forbidden" or "Cloudflare blocked" error:
-
Wait and Retry: Cloudflare blocks may be temporary. Wait 10-15 minutes and try again.
-
Use Browser Cookies (Recommended):
- Log into Twitter/X in your browser
- Install a cookie export extension (e.g., "Cookie-Editor" for Chrome/Firefox)
- Export cookies for
x.comas JSON - Save to
cache/cookies.jsonin the project directory - Run the script again - it will use the cached cookies
-
Try Different Network: Use a different IP/VPN to avoid IP-based blocks
-
Use Twitter Data Export:
- Go to Twitter Settings > Your Account > Download an archive
- Wait 24 hours for the export
- Extract
following.jsandfollower.jsfrom the archive - Place them in a
data/directory - (Note: This requires modifying the code to use the export parser instead)
- 2FA Enabled: Twikit may not work with 2FA. Temporarily disable it or use browser cookies.
- Rate Limits: If you hit rate limits, wait before retrying. The script includes automatic retries.
- Credentials are only used for initial login
- Session cookies are cached locally (not committed to git)
- Never share your
cache/directory