-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbooks
More file actions
executable file
·35 lines (24 loc) · 863 Bytes
/
books
File metadata and controls
executable file
·35 lines (24 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
set -ueo pipefail
read -r -d '' USAGE << EOM || true
$(basename $0) BOOK_TITLE
Search for information about a book
Returns json object with:
title,
authors,
printType, # e.g. "BOOK"
pageCount,
isbn, # ISBN-13
EOM
usage.sh "$USAGE" $@ && exit
[ $# -lt 1 ] && $0 --help && exit
requires jq
# API Reference: https://developers.google.com/books/docs/v1/reference/
# https://developers.google.com/books/docs/v1/getting_started
BOOKS_API_URL='https://www.googleapis.com/books/v1/volumes?q='
searchTerm=${*?Enter book title to search for}
searchTerm=${searchTerm// /+}
url=$BOOKS_API_URL$searchTerm
curl -s $url | \
jq '.items[0].volumeInfo | {title, authors, description, printType, pageCount, isbn: .industryIdentifiers[0].identifier, publishedDate, categories, language, averageRating, ratingsCount }'
# jq '.items[0].volumeInfo'