Skip to content

A python script that tags all Readwise highlights using ChatGPT

Notifications You must be signed in to change notification settings

Duartemartins/readwise-GPT-tagger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Readwise GPT Tagger Project

This project retrieves, processes, and enriches highlights from your Readwise account, generating both CSV and DOCX files that include the highlights and associated tags. If the highlights have fewer than 3 tags, the script uses OpenAI to generate additional relevant tags.

Features

  • Fetches all highlights from a user's Readwise account, iterating through multiple pages of data if necessary.
  • Automatically enriches highlights with additional tags generated by OpenAI if fewer than three are present.
  • Saves highlights with their tags to both a CSV and DOCX file.
  • Logs updated highlights and handles potential errors, such as API rate-limiting.
  • Supports pagination to retrieve large datasets beyond a single API request limit.

Project Structure

  • .gitignore: Specifies files and directories to be ignored by Git.
  • Highlights_with_Tags.csv: CSV file containing highlights with tags.
  • Highlights_with_Tags.docx: DOCX file containing highlights with tags.
  • Highlights.docx: DOCX file containing highlights without additional tags.
  • README.md: This file, explaining project details.
  • readwise.py: Python script responsible for fetching, processing, and saving highlights.
  • requirements.txt: List of dependencies required for the project.
  • updated_highlights_log.txt: Log file recording the highlights that were successfully updated in Readwise with new tags.

Setup

  1. Clone the repository:

    git clone https://github.com/your-username/highlights-project.git
    cd highlights-project
  2. Install the required dependencies:

    pip install -r requirements.txt
  3. Set Environment Variables: You will need two environment variables:

    • READWISE: Your Readwise API token.
    • OPENAI_API_KEY: Your OpenAI API key.

    You can set them like this in your terminal:

    export READWISE=your_readwise_token
    export OPENAI_API_KEY=your_openai_api_key

Usage

  1. Run the readwise.py script to process highlights:

    python readwise.py
  2. Output Files:

    • Highlights_with_Tags.csv: CSV file with highlights and their tags.
    • Highlights_with_Tags.docx: DOCX file with highlights and their tags.
    • updated_highlights_log.txt: Log of successfully updated highlights in Readwise.

Error Handling

  • API Rate-Limiting: The script detects API throttling errors and logs when requests are delayed due to rate limits. You may need to rerun the script after waiting for the cooldown period.
  • Incomplete Tag Generation: If the OpenAI tag generation fails, it logs the error and continues processing other highlights.

Dependencies

This project uses the following Python packages:

stack-data==0.6.3
tornado==6.4
tqdm==4.66.4
traitlets==5.14.2
typing_extensions==4.12.2
tzdata==2024.1
urllib3==2.2.2
wcwidth==0.2.13
requests==2.28.1
python-docx==0.8.11
openai==1.7.0

You can install them by running:

pip install -r requirements.txt

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this project under the terms of the license.

About

A python script that tags all Readwise highlights using ChatGPT

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages