Can someone package this please?

It would be useful in itself but then could be cloned and repurposed.

I do not quie have all the knowledge re javascript modules.

Thank you if possible.

Tony

On Friday, May 22, 2020 at 12:17:20 AM UTC+10, Flan Mou wrote:
>
> Here it is:
>
> ActionGetBookInfoWidget.prototype.invokeAction = 
> function(triggeringWidget,event) {
>   function dateNow() {
>     var set = new Date();
>     var getDate = set.getDate().toString();
>     if (getDate.length == 1){ //example if 1 change to 01
>      getDate = "0"+getDate;
>     }
>     var getMonth = (set.getMonth()+1).toString();
>     if (getMonth.length == 1){
>      getMonth = "0"+getMonth;
>     }
>     var getYear = set.getFullYear().toString();
>     var dateNow = getYear +"-"+ getMonth +"-"+ getDate; //today
>     return dateNow;
>   }
>
>   function createBook(title, authors, publisher, isbn, cover) {
>     var author_line = "* \'\'Authors:\'\' ".concat(authors);
>     var publisher_line = "* \'\'Publisher:\'\' ".concat(publisher);
>     var isbn_line = "* \'\'ISBN:\'\' ".concat(isbn);
>     var date_line = "* \'\'Date Added:\'\' ".concat(dateNow());
>     var cover_line = "[img[".concat(cover,"]]\n");
>     var notes_line = "* \'\'Notes:\'\'";
>     var text = [author_line, publisher_line, isbn_line, date_line, 
> cover_line, notes_line].join("\n");
>     var fields = { tags: "Books", text: text }
>     console.log(fields);
>
>     $tw.wiki.addTiddler(new $tw.Tiddler($tw.wiki.getCreationFields(), fields, 
> {title: title}, $tw.wiki.getModificationFields()));
>   }
>
>   // Create URL
>   var base = "https://openlibrary.org/api/books?bibkeys=ISBN:";;
>   var isbn = this.isbn;
>   var url = base.concat(isbn,"&format=json&jscmd=data");
>   console.log(url);
>
>   // Do HTTP request
>   window.fetch(url)
>     .then(
>       function(response) {
>         if (response.status !== 200) {
>           console.log('Looks like there was a problem. Status Code: ' +
>             response.status);
>           return;
>         }
>
>         response.json().then(function(data) {
>           console.log(JSON.stringify(data));
>           var key = "ISBN:".concat(isbn);
>           var title = data[key]["title"];
>           var publisher = data[key]["publishers"][0]["name"];
>           var authors = data[key]["authors"].map(a => a["name"]).join("|");
>           var cover = data[key]["cover"]["medium"];
>           createBook(title, authors, publisher, isbn, cover);
>           alert("Created page for: " + title);
>         });
>       }
>     )
>     .catch(function(err) {
>     });
>
>   return true; // Action was invoked
> };
>
> There's also the input tiddler that just invokes this action:
>
> New book ISBN: <$edit-text tiddler="$:/state/isbn" tag="input" default=""
> />
>
>
> <$button>
> <$action-getbookinfo $isbn={{$:/state/isbn}}/>
> Add New Book
> </$button>
>
>
> On Thursday, May 21, 2020 at 1:04:49 AM UTC-7, Mat wrote:
>>
>> Flan, please share your solution if you can.
>>
>> Even if you have a special solution there can be bits of knowledge that 
>> are of use (for example, I'm curious how GETs are used as I hope for this 
>> <https://stackoverflow.com/questions/45671606/google-sheets-api-read-single-cell-value-from-public-sheet>
>>  one 
>> day, i.e to fetch cell data from Google Sheets into TW.)
>>
>> Thanks
>>
>> <:-)
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/689294f8-d7c3-4d00-a5d9-408a03ceb00f%40googlegroups.com.

Reply via email to