From d1afdb4aacdc614fd519fe20ced9a1741de484e7 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Thu, 31 Oct 2019 15:44:36 +0100 Subject: [PATCH 1/2] Fix #1074, #1071 --- cps/server.py | 3 +++ 1 file changed, 3 insertions(+) mode change 100644 => 100755 cps/server.py diff --git a/cps/server.py b/cps/server.py old mode 100644 new mode 100755 index e5fe78e4..43792ecd --- a/cps/server.py +++ b/cps/server.py @@ -146,6 +146,9 @@ class WebServer(object): self.unix_socket_file = None def _start_tornado(self): + if os.name == 'nt': + import asyncio + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) log.info('Starting Tornado server on %s', _readable_listen_address(self.listen_address, self.listen_port)) # Max Buffersize set to 200MB ) From 222797e6312a67f1a7eb65b5644010e72c214fb6 Mon Sep 17 00:00:00 2001 From: zhiyue Date: Fri, 22 Nov 2019 00:12:05 +0800 Subject: [PATCH 2/2] support douban book search using apikey --- cps/static/js/get_meta.js | 69 +++++++++++++++++++++++++++--------- cps/templates/book_edit.html | 5 +-- cps/templates/search.html | 3 ++ 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/cps/static/js/get_meta.js b/cps/static/js/get_meta.js index cf079ba7..a453b092 100644 --- a/cps/static/js/get_meta.js +++ b/cps/static/js/get_meta.js @@ -19,15 +19,15 @@ * Google Books api document: https://developers.google.com/books/docs/v1/using * Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only) */ -/* global _, i18nMsg, tinymce */ -// var dbResults = []; +/* global _, i18nMsg, tinymce */ +var dbResults = []; var ggResults = []; $(function () { var msg = i18nMsg; - /*var douban = "https://api.douban.com"; - var dbSearch = "/v2/book/search";*/ - // var dbDone = true; + var douban = "https://api.douban.com"; + var dbSearch = "/v2/book/search"; + var dbDone = true; var google = "https://www.googleapis.com"; var ggSearch = "/books/v1/volumes"; @@ -43,12 +43,22 @@ $(function () { function populateForm (book) { tinymce.get("description").setContent(book.description); + var uniqueTags = []; + $.each(book.tags, function(i, el) { + if ($.inArray(el, uniqueTags) === -1) uniqueTags.push(el); + }); + $("#bookAuthor").val(book.authors); $("#book_title").val(book.title); - $("#tags").val(book.tags.join(",")); + $("#tags").val(uniqueTags.join(",")); $("#rating").data("rating").setValue(Math.round(book.rating)); $(".cover img").attr("src", book.cover); $("#cover_url").val(book.cover); + $("#pubdate").val(book.publishedDate); + $("#publisher").val(book.publisher) + if (book.series != undefined) { + $("#series").val(book.series) + } } function showResult () { @@ -56,10 +66,24 @@ $(function () { if (showFlag === 1) { $("#meta-info").html(""); } - if (!ggDone) { + if (!ggDone && !dbDone) { $("#meta-info").html("

" + msg.no_result + "

"); return; } + function formatDate (date) { + var d = new Date(date), + month = '' + (d.getMonth() + 1), + day = '' + d.getDate(), + year = d.getFullYear(); + + if (month.length < 2) + month = '0' + month; + if (day.length < 2) + day = '0' + day; + + return [year, month, day].join('-'); + } + if (ggDone && ggResults.length > 0) { ggResults.forEach(function(result) { var book = { @@ -72,8 +96,7 @@ $(function () { tags: result.volumeInfo.categories || [], rating: result.volumeInfo.averageRating || 0, cover: result.volumeInfo.imageLinks ? - result.volumeInfo.imageLinks.thumbnail : - "/static/generic_cover.jpg", + result.volumeInfo.imageLinks.thumbnail : "/static/generic_cover.jpg", url: "https://books.google.com/books?id=" + result.id, source: { id: "google", @@ -91,19 +114,30 @@ $(function () { }); ggDone = false; } - /*if (dbDone && dbResults.length > 0) { + if (dbDone && dbResults.length > 0) { dbResults.forEach(function(result) { + if (result.series){ + var series_title = result.series.title + } + var date_fomers = result.pubdate.split("-") + var publishedYear = parseInt(date_fomers[0]) + var publishedMonth = parseInt(date_fomers[1]) + var publishedDate = new Date(publishedYear, publishedMonth-1, 1) + + publishedDate = formatDate(publishedDate) + var book = { id: result.id, title: result.title, authors: result.author || [], description: result.summary, publisher: result.publisher || "", - publishedDate: result.pubdate || "", + publishedDate: publishedDate || "", tags: result.tags.map(function(tag) { - return tag.title; + return tag.title.toLowerCase().replace(/,/g, "_"); }), rating: result.rating.average || 0, + series: series_title || "", cover: result.image, url: "https://book.douban.com/subject/" + result.id, source: { @@ -125,7 +159,7 @@ $(function () { $("#book-list").append($book); }); dbDone = false; - }*/ + } } function ggSearchBook (title) { @@ -148,9 +182,10 @@ $(function () { }); } - /*function dbSearchBook (title) { + function dbSearchBook (title) { + apikey="0df993c66c0c636e29ecbb5344252a4a" $.ajax({ - url: douban + dbSearch + "?q=" + title + "&fields=all&count=10", + url: douban + dbSearch + "?apikey=" + apikey + "&q=" + title + "&fields=all&count=10", type: "GET", dataType: "jsonp", jsonp: "callback", @@ -166,13 +201,13 @@ $(function () { $("#show-douban").trigger("change"); } }); - }*/ + } function doSearch (keyword) { showFlag = 0; $("#meta-info").text(msg.loading); if (keyword) { - // dbSearchBook(keyword); + dbSearchBook(keyword); ggSearchBook(keyword); } } diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index 60421ea6..e734698a 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -219,8 +219,8 @@