Last active
May 24, 2023 02:21
-
-
Save mgmarlow/4558e133f43434f2f238c4803a6b5a1f to your computer and use it in GitHub Desktop.
Export Oku book collection as json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[.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