Skip to content

Instantly share code, notes, and snippets.

@Utopiah
Created February 16, 2022 21:32
Show Gist options
  • Save Utopiah/1c748c68adc016993b3c95f83dca603e to your computer and use it in GitHub Desktop.
Save Utopiah/1c748c68adc016993b3c95f83dca603e to your computer and use it in GitHub Desktop.
#!/bin/bash
for X in $(ls -d *highlights); do
TITLE=$(cat $(echo $X|sed "s/.highlights//").metadata | jq -r .visibleName)
HIGHLIGHTS=$(cat $X/*json | jq '.highlights[][] | {text} | add' -r)
DATA=""
IFS=$'\n'
for h in $HIGHLIGHTS; do
if [ $(echo $h|wc -c) -gt 2 ]; then
NEWDATA="{\"text\": \"$h\",\"title\": \"$TITLE\",\"author\": \"Fabien Benetou\"}"
if [ -z "$DATA" ]; then
DATA=$NEWDATA
else
DATA="$DATA,$NEWDATA"
fi
fi
done
curl --request POST --url https://readwise.io/api/v2/highlights/ \
-H "Authorization: Token $RWIO_TOKEN" \
-H 'Content-Type: application/json' \
--data '{"highlights":['"$NEWDATA"']}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment