Added google scholar as metadata provider

This commit is contained in:
Ozzie Isaacs 2021-05-16 13:24:42 +02:00
parent decc2a9c79
commit 251780bed6
8 changed files with 415 additions and 313 deletions

View File

@ -54,6 +54,12 @@ try:
except ImportError:
greenlet_Version = None
try:
from scholarly import scholarly
scholarly_version = _(u'installed')
except ImportError:
scholarly_version = _(u'not installed')
from . import services
about = flask.Blueprint('about', __name__)
@ -79,6 +85,7 @@ _VERSIONS = OrderedDict(
iso639=isoLanguages.__version__,
pytz=pytz.__version__,
Unidecode = unidecode_version,
Scholarly = scholarly_version,
Flask_SimpleLDAP = u'installed' if bool(services.ldap) else None,
python_LDAP = services.ldapVersion if bool(services.ldapVersion) else None,
Goodreads = u'installed' if bool(services.goodreads_support) else None,

View File

@ -27,6 +27,15 @@ import json
from shutil import copyfile
from uuid import uuid4
# Improve this to check if scholarly is available in a global way, like other pythonic libraries
have_scholar = True
try:
from scholarly import scholarly
except ImportError:
have_scholar = False
pass
from babel import Locale as LC
from babel.core import UnknownLocaleError
from flask import Blueprint, request, flash, redirect, url_for, abort, Markup, Response
@ -1058,6 +1067,23 @@ def convert_bookformat(book_id):
flash(_(u"There was an error converting this book: %(res)s", res=rtn), category="error")
return redirect(url_for('editbook.edit_book', book_id=book_id))
@editbook.route("/scholarsearch/<query>",methods=['GET'])
@login_required_if_no_ano
@edit_required
def scholar_search(query):
if have_scholar:
scholar_gen = scholarly.search_pubs(' '.join(query.split('+')))
i=0
result = []
for publication in scholar_gen:
del publication['source']
result.append(publication)
i+=1
if(i>=10):
break
return Response(json.dumps(result),mimetype='application/json')
else:
return []
@editbook.route("/ajax/editbooks/<param>", methods=['POST'])
@login_required_if_no_ano

View File

@ -1498,7 +1498,7 @@ body > div.container-fluid > div.row-fluid > div.col-sm-10 > div.discover > form
}
#books > .cover > a:hover, #books_rand > .cover > a:hover, .book.isotope-item > .cover > a:hover, body > div.container-fluid > div.row-fluid > div.col-sm-10 > div.discover > form > div.col-sm-12 > div.col-sm-12 > div.col-sm-2 > a:hover {
outline: solid var(--color-secondary);
/* outline: solid var(--color-secondary); */
font-size: 50px;
-o-transition: outline 0s;
transition: outline 0s;
@ -3133,7 +3133,7 @@ div.btn-group[role=group][aria-label="Download, send to Kindle, reading"] > div.
float: left
}
#add-to-shelf, #btnGroupDrop1, #read-in-browser, #sendbtn, .book-meta .btn-toolbar > .btn-group > .btn-group:nth-child(1) > a:first-of-type, .book-meta .btn-toolbar > .btn-group > .btn-warning, .btn-toolbar > .btn-group > #btnGroupDrop2, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 {
#add-to-shelf, #btnGroupDrop1, #readbtn, #sendbtn, .book-meta .btn-toolbar > .btn-group > .btn-group:nth-child(1) > a:first-of-type, .book-meta .btn-toolbar > .btn-group > .btn-warning, .btn-toolbar > .btn-group > #btnGroupDrop2, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 {
background: 0 0;
color: transparent;
width: 50px;
@ -3142,20 +3142,16 @@ div.btn-group[role=group][aria-label="Download, send to Kindle, reading"] > div.
overflow: hidden;
padding: 0
}
#readbtn {
height: 100%;
padding: 16px;
}
#add-to-shelf > span.caret, #btnGroupDrop1 > span.caret, #read-in-browser > span.caret, .btn-toolbar > .btn-group > #btnGroupDrop2 > span.caret, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 > span.caret {
padding-bottom: 5px
}
#add-to-shelf > span, #btnGroupDrop1 > span, #read-in-browser > span, #sendbtn > span, .book-meta .btn-toolbar > .btn-group > .btn-group:nth-child(1) > a:first-of-type > span, .book-meta .btn-toolbar > .btn-group > .btn-warning > span, .btn-toolbar > .btn-group > #btnGroupDrop2 > span, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 > span {
#add-to-shelf > span, #btnGroupDrop1 > span, #readbtn > span, #sendbtn > span, .book-meta .btn-toolbar > .btn-group > .btn-group:nth-child(1) > a:first-of-type > span, .book-meta .btn-toolbar > .btn-group > .btn-warning > span, .btn-toolbar > .btn-group > #btnGroupDrop2 > span, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 > span {
color: hsla(0, 0%, 100%, .7)
}
#add-to-shelf:hover span, #btnGroupDrop1:hover > span, #read-in-browser:hover > span, #sendbtn:hover > span, .book-meta .btn-toolbar > .btn-group > .btn-group:nth-child(1) > a:first-of-type:hover > span, .book-meta .btn-toolbar > .btn-group > .btn-warning:hover > span, .btn-toolbar > .btn-group > #btnGroupDrop2:hover > span, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2:hover > span {
#add-to-shelf:hover span, #btnGroupDrop1:hover > span, #readbtn:hover > span, #sendbtn:hover > span, .book-meta .btn-toolbar > .btn-group > .btn-group:nth-child(1) > a:first-of-type:hover > span, .book-meta .btn-toolbar > .btn-group > .btn-warning:hover > span, .btn-toolbar > .btn-group > #btnGroupDrop2:hover > span, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2:hover > span {
color: #fff
}
@ -3165,13 +3161,13 @@ div.btn-group[role=group][aria-label="Download, send to Kindle, reading"] > div.
font-size: 18px
}
#sendbtn > span, .book-meta .btn-toolbar > .btn-group > .btn-group:nth-child(1) > a:first-of-type > span, .book-meta .btn-toolbar > .btn-group > .btn-warning > span.glyphicon-edit {
#sendbtn > span, #readbtn > span, .book-meta .btn-toolbar > .btn-group > .btn-group:nth-child(1) > a:first-of-type > span, .book-meta .btn-toolbar > .btn-group > .btn-warning > span.glyphicon-edit {
font-size: 16px;
line-height: 54px;
width: 100%
}
#read-in-browser > span.glyphicon-eye-open:before, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 > span.glyphicon-eye-open:before {
#readbtn > span.glyphicon-book:before, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 > span.glyphicon-book:before {
content: "\e352";
font-family: Glyphicons Regular, serif;
font-size: 18px;
@ -3294,7 +3290,9 @@ div.btn-group[role=group][aria-label="Download, send to Kindle, reading"] .dropd
-ms-transform-origin: center top;
transform-origin: center top;
border: 0;
left: 0 !important
left: 0 !important;
max-height: 80%;
overflow-y: auto;
}
.dropdown-menu > li > a {
@ -5163,11 +5161,11 @@ body.login > div.navbar.navbar-default.navbar-static-top > div > div.navbar-head
right: 5px
}
#read-in-browser[aria-expanded=true], #shelf-actions > .btn-group.open, .downloadBtn.open, .profileDrop[aria-expanded=true] {
#shelf-actions > .btn-group.open, .downloadBtn.open, .profileDrop[aria-expanded=true] {
pointer-events: none
}
#btnGroupDrop1[aria-expanded=true] > span, #read-in-browser[aria-expanded=true] > span, #shelf-actions > .btn-group.open > #add-to-shelf > span {
#btnGroupDrop1[aria-expanded=true] > span, #shelf-actions > .btn-group.open > #add-to-shelf > span {
color: #fff
}
@ -7484,14 +7482,14 @@ body.edituser.admin > div.container-fluid > div.row-fluid > div.col-sm-10 > div.
margin-left: 8px
}
#read-in-browser > span.caret, .btn-toolbar > .btn-group > #btnGroupDrop2 > span.caret, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 > span.caret {
.btn-toolbar > .btn-group > #btnGroupDrop2 > span.caret, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 > span.caret {
position: absolute;
margin-left: 0;
left: 33px;
top: 28px
}
#read-in-browser > span.glyphicon-eye-open:before, .btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 > span.glyphicon-eye-open:before {
.btn-toolbar > .btn-group > .btn-group > #btnGroupDrop2 > span.glyphicon-eye-open:before {
margin-left: 8px
}
@ -7892,7 +7890,7 @@ body.mailset > div.container-fluid > div > div.col-sm-10 > div.discover .glyphic
}
}
#sendbtn2 {
#sendbtn2, #read-in-browser {
background: 0 0;
color: transparent;
width: 50px;
@ -7902,15 +7900,15 @@ body.mailset > div.container-fluid > div > div.col-sm-10 > div.discover .glyphic
padding: 0
}
#sendbtn2 > span {
#sendbtn2 > span, #read-in-browser > span {
color: hsla(0, 0%, 100%, .7)
}
#sendbtn2 > span.glyphicon-send:before {
#sendbtn2 > span.glyphicon-send:before, #read-in-browser > span.glyphicon-book:before {
margin-left: 8px
}
#sendbtn2 > span.caret {
#sendbtn2> span.caret, #read-in-browser > span.caret {
position: absolute;
margin-left: 0;
left: 33px;
@ -7918,11 +7916,11 @@ body.mailset > div.container-fluid > div > div.col-sm-10 > div.discover .glyphic
padding-bottom: 5px
}
#sendbtn2:focus span, #sendbtn2:hover span {
#sendbtn2:focus span, #sendbtn2:hover span, #read-in-browser:focus span, #read-in-browser:hover span {
color: #fff
}
#sendbtn2[aria-expanded=true] {
#sendbtn2[aria-expanded=true], #read-in-browser[aria-expanded=true] {
pointer-events: none
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 175 KiB

View File

@ -19,11 +19,12 @@
* 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)
* ComicVine api document: https://comicvine.gamespot.com/api/documentation
*/
*/
/* global _, i18nMsg, tinymce */
var dbResults = [];
var ggResults = [];
var cvResults = [];
var gsResults = [];
$(function () {
var msg = i18nMsg;
@ -39,6 +40,10 @@ $(function () {
var cvSearch = "/api/search/";
var cvDone = 0;
var googlescholar = window.location.href.split('/admin/book')[0];
var gsSearch = "/scholarsearch/"
var gsDone = 0;
var showFlag = 0;
var templates = {
@ -59,8 +64,10 @@ $(function () {
$("#book_title").val(book.title);
$("#tags").val(uniqueTags.join(","));
$("#rating").data("rating").setValue(Math.round(book.rating));
if(book.cover !== null){
$(".cover img").attr("src", book.cover);
$("#cover_url").val(book.cover);
}
$("#pubdate").val(book.publishedDate);
$("#publisher").val(book.publisher);
if (typeof book.series !== "undefined") {
@ -75,7 +82,8 @@ $(function () {
}
if ((ggDone === 3 || (ggDone === 1 && ggResults.length === 0)) &&
(dbDone === 3 || (dbDone === 1 && dbResults.length === 0)) &&
(cvDone === 3 || (cvDone === 1 && cvResults.length === 0))) {
(cvDone === 3 || (cvDone === 1 && cvResults.length === 0)) &&
(gsDone === 3 || (gsDone === 1 && gsResults.length === 0))) {
$("#meta-info").html("<p class=\"text-danger\">" + msg.no_result + "</p>");
return;
}
@ -94,6 +102,9 @@ $(function () {
return [year, month, day].join("-");
}
function generateID (title) {
return title.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0).toString().substr(0,12);
}
if (ggResults.length > 0) {
if (ggDone < 2) {
@ -130,6 +141,42 @@ $(function () {
}
}
if (gsResults.length > 0) {
if (gsDone < 2) {
gsResults.forEach(function(result) {
var book = {
id: generateID(result.bib.title),
title: result.bib.title,
authors: result.bib.author || [],
description: result.bib.abstract || "",
publisher: result.bib.venue || "",
publishedDate: result.bib.pub_year ? result.bib.pub_year+"-01-01" : "",
tags: [],
rating: 0,
series: "",
cover: null,
url: result.pub_url || result.eprint_url || "",
source: {
id: "googlescholar",
description: "Google Scholar",
link: "https://scholar.google.com/"
}
}
var $book = $(templates.bookResult(book));
$book.find("img").on("click", function () {
populateForm(book);
});
$("#book-list").append($book);
});
gsDone = 2;
}
else {
gsDone = 3;
}
}
if (dbResults.length > 0) {
if (dbDone < 2) {
dbResults.forEach(function(result) {
@ -295,17 +342,35 @@ $(function () {
});
}
function gsSearchBook (title) {
$.ajax({
url: googlescholar + gsSearch + title.replace(/\s+/gm,'+'),
type: "GET",
dataType: "json",
success: function success(data) {
gsResults = data;
},
complete: function complete() {
gsDone = 1;
showResult();
$("#show-googlescholar").trigger("change");
}
})
}
function doSearch (keyword) {
showFlag = 0;
dbDone = ggDone = cvDone = 0;
dbResults = [];
ggResults = [];
cvResults = [];
gsResults = [];
$("#meta-info").text(msg.loading);
if (keyword) {
dbSearchBook(keyword);
ggSearchBook(keyword);
cvSearchBook(keyword);
gsSearchBook(keyword);
}
}

View File

@ -246,6 +246,10 @@
<input type="checkbox" id="show-comics" class="pill" data-control="comicvine" checked>
<label for="show-comics">ComicVine <span class="glyphicon glyphicon-ok"></span></label>
<input type="checkbox" id="show-googlescholar" class="pill" data-control="googlescholar" checked>
<label for="show-googlescholar">Google Scholar <span class="glyphicon glyphicon-ok"></span></label>
</div>
<div id="meta-info">
@ -267,7 +271,7 @@
<img class="pull-left img-responsive"
data-toggle="modal"
data-target="#metaModal"
src="<%= cover %>"
src="<%= cover || "{{ url_for('static', filename='img/academicpaper.svg') }}" %>"
alt="Cover"
>
<div class="media-body">

View File

@ -57,7 +57,7 @@
<div class="btn-group" role="group">
{% if reader_list|length > 1 %}
<button id="read-in-browser" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-eye-open"></span> {{_('Read in Browser')}}
<span class="glyphicon glyphicon-book"></span> {{_('Read in Browser')}}
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="read-in-browser">
@ -66,7 +66,7 @@
{%endfor%}
</ul>
{% else %}
<a target="_blank" href="{{url_for('web.read_book', book_id=entry.id, book_format=reader_list[0])}}" id="readbtn" class="btn btn-primary" role="button"><span class="glyphicon glyphicon-eye-open"></span> {{_('Read in Browser')}} - {{reader_list[0]}}</a>
<a target="_blank" href="{{url_for('web.read_book', book_id=entry.id, book_format=reader_list[0])}}" id="readbtn" class="btn btn-primary" role="button"><span class="glyphicon glyphicon-book"></span> {{_('Read in Browser')}} - {{reader_list[0]}}</a>
{% endif %}
</div>
{% endif %}

View File

@ -32,6 +32,7 @@ SQLAlchemy-Utils>=0.33.5,<0.38.0
# extracting metadata
lxml>=3.8.0,<4.7.0
rarfile>=2.7
scholarly>=1.2.0, <1.3
# other
natsort>=2.2.0,<7.2.0