Skip to content

Instantly share code, notes, and snippets.

@mgmarlow
Last active May 24, 2023 02:21
Show Gist options
  • Save mgmarlow/4558e133f43434f2f238c4803a6b5a1f to your computer and use it in GitHub Desktop.
Save mgmarlow/4558e133f43434f2f238c4803a6b5a1f to your computer and use it in GitHub Desktop.
Export Oku book collection as json
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
user=mgmarlow
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
echo 'Usage: getbooks (read|to-read|reading)'
exit
fi
if ! command -v jq &> /dev/null
then
echo "jq not found. Try 'brew install jq'."
exit
fi
main() {
if [ $# -eq 0 ]; then
echo "Must specify collection, e.g. 'getbooks read'"
exit
fi
url="https://oku.club/api/collections/user/${user}/${1}"
echo "Fetching ${url}..."
filename="oku-export-${1}.csv"
curl -s $url | jq -rf ./out.jq > $filename
echo "Wrote ${filename}."
}
main "$@"
[.books[]
| {
title: .title,
author: .authors[0].name,
added_at: .addedAt,
published_date: .publishedDate,
isbn_13: .isbn13,
page_count: .pageCount
}]
| (map(keys) | add | unique) as $cols
| map(. as $row | $cols | map($row[.])) as $rows
| $cols, $rows[]
| @csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment