A Python script to fetch your Twitter bookmarks and optionally categorize them by topic using AI.
- Reports total bookmark count on your Twitter profile
- Fetches up to 150 Twitter bookmarks via the Twitter API
- Saves bookmarks in multiple formats (JSON, text, and CSV)
- Optional AI categorization using your choice of:
- OpenAI (ChatGPT)
- Anthropic (Claude)
- Google (Gemini)
- xAI (Grok)
- Works without AI - just fetches and lists bookmarks
- Interactive prompts to:
- Export bookmarks to CSV format
- Delete bookmarks from Twitter after saving
- Shows remaining bookmark count after deletion
pip install tweepyFor AI categorization, install the provider you want to use:
# For OpenAI or Grok
pip install openai
# For Claude
pip install anthropic
# For Gemini
pip install google-generativeaiOr install all at once:
pip install -r requirements.txtOption A: Create a config.py file (recommended)
# Copy the example config
cp config_example.py config.py
# Edit config.py with your API keysOption B: Edit the script directly
Edit the credentials section in fetch_twitter_bookmarks.py
- Go to https://developer.twitter.com/en/portal/dashboard
- Create a project and app
- Generate API keys and tokens
- Add them to your config
Set AI_PROVIDER in your config to one of:
"none"- No categorization (default)"openai"- Use ChatGPT"claude"- Use Claude"gemini"- Use Gemini"grok"- Use Grok
Then add the corresponding API key.
python fetch_twitter_bookmarks.pyJust set AI_PROVIDER = "none" (default) - the script will:
- Fetch your Twitter bookmarks
- Save them to
twitter_bookmarks.json - Save them to
twitter_bookmarks_text.txt - Display all bookmarks in the console
Only requires the Twitter API credentials.
Set AI_PROVIDER = "openai" (or another provider) - the script will also:
- Categorize bookmarks into topics using AI
- Save categorized bookmarks to
twitter_bookmarks_categorized.txt - Display bookmarks grouped by category
- Show a category breakdown
Requires both Twitter API and your chosen AI provider API key.
- twitter_bookmarks.json - Full structured data with all metadata
- twitter_bookmarks_text.txt - Plain text format with tweet content
- twitter_bookmarks_categorized.txt - Tweets organized by category (if AI is enabled)
- twitter_bookmarks.csv - CSV format (if you choose to export during the prompt)
After fetching your bookmarks, the script will ask:
Would you like to export bookmarks to CSV? (yes/no):
- Type
yesoryto export bookmarks to a CSV file - CSV includes columns: number, author, text, URL (and category if AI is enabled)
- Perfect for importing into Excel, Google Sheets, or other tools
Would you like to delete the bookmarks from this report? (yes/no):
- WARNING: This permanently deletes bookmarks from your Twitter account
- Includes a confirmation prompt to prevent accidental deletion
- Use this to clean up your bookmarks after saving them locally
- Useful for managing Twitter's bookmark limit or organizing your saved tweets
When AI categorization is enabled, tweets are categorized into:
- AI & Machine Learning
- Programming & Development
- Business & Entrepreneurship
- Marketing & Sales
- Productivity & Tools
- Science & Research
- Politics & Current Events
- Personal Development
- Entertainment & Media
- Sports & Fitness
- Health & Wellness
- Finance & Investing
- Education & Learning
- Climate & Environment
- Design & Creativity
- News & Journalism
- Cryptocurrency & Web3
- Social Media & Content Creation
- Other
- Free tier available
- Get from: https://developer.twitter.com/en/portal/dashboard
- Pay-per-use
- Get from: https://platform.openai.com/api-keys
- Pay-per-use
- Get from: https://console.anthropic.com/
- Free tier available
- Get from: https://makersuite.google.com/app/apikey
- Pay-per-use
- Get from: https://x.ai/
Here's what happens when you run the script:
- Count: Reports total number of bookmarks on your Twitter profile
- Fetch: Downloads up to 150 most recent bookmarks
- Save: Saves bookmarks to JSON and text files
- Categorize (optional): Uses AI to categorize tweets by topic
- Display: Shows all bookmarks in the console
- CSV Export (prompt): Asks if you want to export to CSV
- Delete (prompt): Asks if you want to delete bookmarks from Twitter
- Summary: Shows remaining bookmark count after deletion (if applicable)
The script is fully interactive and safe - you control what happens at each step!
================================================================================
TWITTER BOOKMARKS FETCHER
================================================================================
Checking your Twitter profile for total bookmarks...
================================================================================
TOTAL BOOKMARKS ON YOUR PROFILE: 347
================================================================================
⚠ Note: You have 347 total bookmarks.
This script will fetch and process the most recent 150 bookmarks.
Fetching your Twitter bookmarks...
This helps you understand:
- How many bookmarks you have in total
- What percentage you're processing (150 out of total)
- Whether you need to run the script multiple times to process all bookmarks
- How many remain after deletion
"No AI provider selected"
- AI categorization is disabled. This is normal if
AI_PROVIDER = "none" - The script will still fetch and display all bookmarks
"API key not configured"
- Make sure you've added your API keys to config.py
- Check that the key doesn't start with "your_"
"Required library not installed"
- Install the required library for your chosen AI provider
- See installation instructions above
Twitter API errors
- Verify your Twitter API credentials are correct
- Ensure you have the necessary API access level (elevated access for bookmarks)
"Failed to delete Tweet ID"
- Some bookmarks may fail to delete if they've already been removed
- The script will continue deleting remaining bookmarks
"Counting total bookmarks (this may take a moment)..."
- For users with many bookmarks (1000+), the counting process may take 30-60 seconds
- The script must paginate through all bookmarks to get an accurate count
- This only happens once at the beginning
- The script first counts ALL your bookmarks to give you the total
- The Twitter API returns a maximum of 100 bookmarks per request
- The script automatically paginates to fetch up to 150 bookmarks for processing
- If you have more than 150 bookmarks, you can run the script multiple times
- AI categorization processes tweets in batches of 10 for efficiency
- You only need to install the AI library for the provider you're using
- The remaining count after deletion is an estimate based on the initial count
- Double confirmation for bookmark deletion to prevent accidents
- All data is saved locally before any deletion occurs
- CSV export is optional and non-destructive
- Bookmark deletion is optional - you can keep bookmarks on Twitter if desired
- Clear warning messages before any destructive actions