Skip to content

Commit

Permalink
fix!: migrate to new raindrop endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
thenbe committed Aug 28, 2024
1 parent 04ec287 commit 286c1f5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ nix run github:thenbe/fzf-raindrop
> Bookmarks will be pulled _automatically_ only when you launch `fzf-raindrop` for the first time. After that, you can pull the latest bookmarks by running the following command.
```sh
FZF_RAINDROP_COOKIE="..." fzf-raindrop update
FZF_RAINDROP_TOKEN="..." fzf-raindrop update

# or using nix
FZF_RAINDROP_COOKIE="..." nix run github:thenbe/fzf-raindrop -- update
FZF_RAINDROP_TOKEN="..." nix run github:thenbe/fzf-raindrop -- update
```

### Key maps
Expand Down Expand Up @@ -64,18 +64,26 @@ Clone this repo and make sure you have the required [dependencies](#dependencies

## Configuration

| Env Var | Required | Default | Example | Notes |
| ----------------------- | -------- | --------------------------------- | ---------------------- | ----------------------------- |
| `OPENER` | no | `xdg-open`, `open` | "mimeo" or "firefox" | Program used to launch URLs |
| `FZF_RAINDROP_COOKIE` | yes | | "connect.sid=s%123..." | Get from browser's devtools\* |
| `FZF_RAINDROP_DATA_DIR` | | `$HOME/.local/share/fzf-raindrop` | | |
| Env Var | Required | Default | Example | Notes |
| ----------------------- | -------- | --------------------------------- | -------------------- | --------------------------- |
| `OPENER` | no | `xdg-open`, `open` | "mimeo" or "firefox" | Program used to launch URLs |
| `FZF_RAINDROP_TOKEN` | yes | | "a1b2c3..." | Get from Raindrop app\* |
| `FZF_RAINDROP_DATA_DIR` | | `$HOME/.local/share/fzf-raindrop` | | |

> \* Unfortunately, the [Raindrop API](https://developer.raindrop.io/) does not expose an endpoint to [export all bookmarks](https://help.raindrop.io/backups/#downloading-a-backup) using a bearer token. See [issue](https://github.com/thenbe/fzf-raindrop/issues/1).
### Generate a Raindrop token

A test token is [sufficient](https://developer.raindrop.io/v1/authentication/token) for our needs. To create one:

1. Go to the [Raindrop app settings](https://app.raindrop.io/settings/integrations).
1. Click `Create new app`. Name it `fzf-raindrop`.
1. Click on the item you just created.
1. Click on `Create test token`.

## Dependencies

- [`duckdb`](https://github.com/duckdb/duckdb)
- [`fzf`](https://github.com/junegunn/fzf)
- `jq`

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
nativeBuildInputs = [ pkgs.makeWrapper ];
postFixup = with pkgs; ''
wrapProgram "$out/bin/fzf-raindrop" \
--prefix PATH : "${lib.makeBinPath [ duckdb fzf ]}"
--prefix PATH : "${lib.makeBinPath [ duckdb fzf jq ]}"
'';
installPhase = ''
mkdir -p $out/bin
Expand Down
32 changes: 29 additions & 3 deletions fzf-raindrop
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,37 @@ MODIFIED=$(stat -c %y "$DATA_FILE" | cut -d'.' -f1)
# Allow users to define a custom OPENER, fallback to auto-detection if not defined
OPENER=${OPENER:-$(command -v xdg-open || command -v open)}

# Get list of backups
get_backups() {
curl 'https://api.raindrop.io/rest/v1/backups' \
-H "Authorization: Bearer $FZF_RAINDROP_TOKEN"
}

# Get latest backup id
get_latest_backup_id() {
get_backups | jq -r '.items | max_by(.created) | ._id'
}

# Get latest backup creation date
get_latest_backup_date() {
get_backups | jq -r '.items | max_by(.created) | .created'
}

# Download all bookmarks from Raindrop
download_bookmarks() {
echo "Pulling latest bookmarks from Raindrop"
curl 'https://api.raindrop.io/v1/raindrops/0/export.csv' \
-H "Cookie: $FZF_RAINDROP_COOKIE" \

echo "Looking for most recent backup..."
# Look for the most recent backup
BACKUP_ID=$(get_latest_backup_id)
BACKUP_DATE=$(get_latest_backup_date)
echo "Found most recent backup. backup_created: $BACKUP_DATE, backup_id: $BACKUP_ID"

# Download backup file
echo "Downloading most recent backup..."
curl -L "https://api.raindrop.io/rest/v1/backup/$BACKUP_ID.csv" \
-H "Authorization: Bearer $FZF_RAINDROP_TOKEN" \
--compressed \
-o "$DATA_FILE_TEMP"

mv "$DATA_FILE_TEMP" "$DATA_FILE"
Expand Down Expand Up @@ -78,7 +104,7 @@ COPY (
) TO '/dev/stdout' WITH (FORMAT CSV, HEADER)
" |
# xsv table --width=2 --condense=75 |
fzf --multi --layout=reverse --header-lines=1 --header "Updated: $MODIFIED" --history="$FZF_BOOKMARKS_HISTORY" |
fzf --multi --layout=reverse --header-lines=1 --header "Downloaded at: $MODIFIED" --history="$FZF_BOOKMARKS_HISTORY" |
awk --field-separator=, '{print $1}' |
xargs -I {} duckdb -c "COPY(SELECT url FROM '$DATA_FILE' WHERE id_2 = {}) TO '/dev/stdout'" |
xargs -I {} "$OPENER" "{}"

0 comments on commit 286c1f5

Please sign in to comment.