Commit 26cc64bd authored by cbartondock's avatar cbartondock

Use google scholar to fetch metadata

parent c0623a94
...@@ -27,6 +27,15 @@ import json ...@@ -27,6 +27,15 @@ import json
from shutil import copyfile from shutil import copyfile
from uuid import uuid4 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 flask import Blueprint, request, flash, redirect, url_for, abort, Markup, Response from flask import Blueprint, request, flash, redirect, url_for, abort, Markup, Response
from flask_babel import gettext as _ from flask_babel import gettext as _
from flask_login import current_user, login_required from flask_login import current_user, login_required
...@@ -996,6 +1005,26 @@ def convert_bookformat(book_id): ...@@ -996,6 +1005,26 @@ def convert_bookformat(book_id):
flash(_(u"There was an error converting this book: %(res)s", res=rtn), category="error") 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)) 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 'Scholarly not installed'
@editbook.route("/ajax/editbooks/<param>", methods=['POST']) @editbook.route("/ajax/editbooks/<param>", methods=['POST'])
@login_required_if_no_ano @login_required_if_no_ano
@edit_required @edit_required
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
...@@ -227,6 +227,10 @@ ...@@ -227,6 +227,10 @@
<input type="checkbox" id="show-comics" class="pill" data-control="comicvine" checked> <input type="checkbox" id="show-comics" class="pill" data-control="comicvine" checked>
<label for="show-comics">ComicVine <span class="glyphicon glyphicon-ok"></span></label> <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>
<div id="meta-info"> <div id="meta-info">
...@@ -248,7 +252,7 @@ ...@@ -248,7 +252,7 @@
<img class="pull-left img-responsive" <img class="pull-left img-responsive"
data-toggle="modal" data-toggle="modal"
data-target="#metaModal" data-target="#metaModal"
src="<%= cover %>" src="<%= cover || "{{ url_for('static', filename='img/academicpaper.svg') }}" %>"
alt="Cover" alt="Cover"
> >
<div class="media-body"> <div class="media-body">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment