Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.

Dev-MS-Infrastructure-Ops/BookedX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Twitter Bookmarks Fetcher

A Python script to fetch your Twitter bookmarks and optionally categorize them by topic using AI.

Features

  • 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

Quick Start

1. Install Dependencies

pip install tweepy

For 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-generativeai

Or install all at once:

pip install -r requirements.txt

2. Configure API Keys

Option A: Create a config.py file (recommended)

# Copy the example config
cp config_example.py config.py

# Edit config.py with your API keys

Option B: Edit the script directly

Edit the credentials section in fetch_twitter_bookmarks.py

3. Get Twitter API Credentials

  1. Go to https://developer.twitter.com/en/portal/dashboard
  2. Create a project and app
  3. Generate API keys and tokens
  4. Add them to your config

4. (Optional) Configure AI Provider

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.

5. Run the Script

python fetch_twitter_bookmarks.py

Usage Examples

Without AI Categorization

Just 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.

With AI Categorization

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.

Output Files

  1. twitter_bookmarks.json - Full structured data with all metadata
  2. twitter_bookmarks_text.txt - Plain text format with tweet content
  3. twitter_bookmarks_categorized.txt - Tweets organized by category (if AI is enabled)
  4. twitter_bookmarks.csv - CSV format (if you choose to export during the prompt)

Interactive Prompts

After fetching your bookmarks, the script will ask:

1. CSV Export

Would you like to export bookmarks to CSV? (yes/no):
  • Type yes or y to 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

2. Delete Bookmarks

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

Categories

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

API Keys

Twitter API

OpenAI (ChatGPT)

Anthropic (Claude)

Google (Gemini)

xAI (Grok)

Workflow

Here's what happens when you run the script:

  1. Count: Reports total number of bookmarks on your Twitter profile
  2. Fetch: Downloads up to 150 most recent bookmarks
  3. Save: Saves bookmarks to JSON and text files
  4. Categorize (optional): Uses AI to categorize tweets by topic
  5. Display: Shows all bookmarks in the console
  6. CSV Export (prompt): Asks if you want to export to CSV
  7. Delete (prompt): Asks if you want to delete bookmarks from Twitter
  8. Summary: Shows remaining bookmark count after deletion (if applicable)

The script is fully interactive and safe - you control what happens at each step!

Example Output

================================================================================
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

Troubleshooting

"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

Notes

  • 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

Safety Features

  • 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

About

Py script to pull bookmarks from X via API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors