Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 5 fields #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,16 @@ Cover:: {{VALUE:thumbnail}}
ISBN10:: {{VALUE:isbn10}}
ISBN13:: {{VALUE:isbn13}}
URL:: [Goodreads]({{VALUE:goodreadsURL}})
Genre:: {{VALUE:genre}}
PageCount:: {{VALUE:pageCount}}
AverageRating:: {{VALUE:avRating}}
Rating:: {{VALUE:rating}}
Maturity:: {{VALUE:mature}}
Read:: {{VALUE:read}}
Recommender:: {{VALUE:recommender}}
Date:: {{DATE}}
Comment:: {{VALUE:comment}}
BookDescription:: {{VALUE: bookDesc}}

```

Expand All @@ -136,6 +141,11 @@ Author,
publish-date AS "Publish date",
("![coverImg|100](" + Cover + ")") as Cover,
rating AS "Rating",
AverageRating AS "Average Rating",
Maturity AS "Maturity Rating",
PageCount AS "Page Count",
BookDescription AS "Book Description",
Genre,
Recommender,
Comment,
Date,
Expand Down Expand Up @@ -172,6 +182,16 @@ Please find here a definition of the possible variables to be used in your templ

`rating` : Your book rating, /10.

`avRating` : Average rating from all ratings in API.

`genre` : The reported genre of the book.

`pageCount` : Total number of pages in this book.

`mature` : Is this book rated mature or not?

`bookDesc` : What is the blurb of the book?

`read` : If you read the book, this equals 1, otherwise 0 (this helps to filter dataview query).

`recommender` : The person (or organization, etc...) that recommended the book to you.
Expand Down
45 changes: 28 additions & 17 deletions script_googleBooks_quickAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ const API_KEY = "Google Books API Key"
const GOODREADS_URL = "https://www.goodreads.com/search?qid=&q="

module.exports = {
entry: start,
settings: {
name: "Books script",
author: "Elaws",
options: {
[API_KEY]: {
type: "text",
defaultValue: "",
placeholder: "Google Books API Key",
}
},
},
entry: start,
settings: {
name: "Books script",
author: "Elaws",
options: {
[API_KEY]: {
type: "text",
defaultValue: "",
placeholder: "Google Books API Key",
}
},
},
};

let QuickAdd;
Expand Down Expand Up @@ -94,6 +94,7 @@ async function start(params, settings) {
authors: formatList(selectedBook.authors),
isbn10: `${ISBN.ISBN10 ? ISBN.ISBN10 : " "}`,
isbn13: `${ISBN.ISBN13 ? ISBN.ISBN13 : " "}`,

// An URL to the GoodReads page of the book using its ISBN.
// May fail if ISBN returned by Google Books is not in Goodreads database.
goodreadsURL: `${ISBN.ISBN13 ? GOODREADS_URL + ISBN.ISBN13 : (ISBN.ISBN10 ? GOODREADS_URL + ISBN.ISBN10 : " ")}`,
Expand All @@ -102,8 +103,18 @@ async function start(params, settings) {
release: `${selectedBook.publishedDate ? (new Date((selectedBook.publishedDate))).getFullYear() : " "}`,
// Squares of different color to tag Obsidian's note, depending if book has already been read or not.
tag: `${isRead ? "\u{0001F7E7}" : "\u{0001F7E5}"}`,
// Main Category reported for the book
genre: `${selectedBook.categories ? selectedBook.categories : "N/A"}`,
// A rating for the read book, /10.
rating: myRating,
// The global average review * 2 to get /10
avRating: `${selectedBook.averageRating ? selectedBook.averageRating * 2 : 0 }`,
// For mature audiences or not?
mature: `${selectedBook.maturityRating ? selectedBook.maturityRating : "NA" }`,
// Pages reported in book
pageCount: `${selectedBook.pageCount ? selectedBook.pageCount : 0 }`,
// blurb
bookDesc: `${selectedBook.description ? selectedBook.description : "No Description Reported" }`,
// Is the book already read ? 1 if yes, 0 otherwise.
read: `${isRead ? "1" : "0"}`,
// Who recommended the book to me?
Expand Down Expand Up @@ -157,13 +168,13 @@ async function getByQuery(query) {

if(searchResults.error)
{
notice("Request failed");
throw new Error("Request failed");
notice("Request failed");
throw new Error("Request failed");
}

if (searchResults.totalItems == 0) {
notice("No results found.");
throw new Error("No results found.");
notice("No results found.");
throw new Error("No results found.");
}

return searchResults.items;
Expand All @@ -185,7 +196,7 @@ async function apiGet(query) {
let finalURL = new URL(API_URL);

finalURL.searchParams.append("q", query);
finalURL.searchParams.append("key", Settings[API_KEY]);
finalURL.searchParams.append("key", Settings[API_KEY]);

log(finalURL.href);

Expand Down