Readwise Shortlist Sync Bot

This project syncs your Readwise shortlist articles to a SQLite database for easy access and management.

Files

  • readwise-bot.ts - Standalone function version (can be used as cron)
  • readwise-http.ts - HTTP endpoint version with web dashboard ⭐ Recommended
  • README.md - This documentation

Setup

  1. Get your Readwise API token:

  2. Set environment variable:

    • In Val Town, add an environment variable named READWISE_TOKEN
    • Set its value to your Readwise access token

Usage

The readwise-http.ts file provides a web interface and API endpoints:

  • Dashboard: Visit the root URL to see a simple web interface
  • Sync API: POST /sync - Triggers a sync of your shortlist
  • Links API: GET /links?limit=50 - Retrieves saved links from database

Standalone Version

The readwise-bot.ts can be:

  • Run manually by calling the function
  • Set up as a cron job for automatic syncing

Database Schema

The bot creates a readwise_links table with the following fields:

  • id - Unique document ID from Readwise
  • url - Article URL
  • title - Article title
  • author - Article author
  • source - Source publication
  • category - Document category (article, email, etc.)
  • location - Current location (shortlist, archive, etc.)
  • tags - JSON string of tags
  • site_name - Website name
  • word_count - Article word count
  • created_at - When document was created in Readwise
  • updated_at - When document was last updated in Readwise
  • published_date - Original publication date
  • summary - Article summary
  • image_url - Featured image URL
  • reading_progress - Reading progress percentage
  • first_opened_at - When first opened
  • last_opened_at - When last opened
  • saved_at - When saved to Readwise
  • last_moved_at - When last moved between locations
  • synced_at - When synced to our database

Features

  • Incremental sync: Only updates documents that have changed
  • Pagination handling: Automatically handles large shortlists
  • Error handling: Robust error handling and logging
  • Duplicate prevention: Prevents duplicate entries
  • Web dashboard: Simple interface to trigger syncs and view links
  • SQLite compatibility: Properly handles Val Town's SQLite format

API Examples

Sync shortlist

curl -X POST https://your-val-url/sync
curl https://your-val-url/links?limit=20

Scheduling

To run automatically, you can:

  1. Use the standalone readwise-bot.ts version and set it as a cron job
  2. Set up an external service to call the /sync endpoint periodically
  3. Manually trigger syncs through the web dashboard

Environment Variables Required

  • READWISE_TOKEN - Your Readwise API access token

Recent Updates

  • ✅ Fixed SQLite result format handling
  • ✅ Improved error handling for individual document failures
  • ✅ Added proper incremental sync logic
  • ✅ Web dashboard now displays saved articles correctly