From 249fd9037378c611a31ed83d9fdf16170af850e8 Mon Sep 17 00:00:00 2001 From: ange Date: Wed, 13 Jun 2018 20:04:54 +0200 Subject: [PATCH] changes in annotations --- app/getannot.py | 12 +++--------- app/templates/annotations.html | 2 +- app/templates/results_annot.html | 2 +- app/views.py | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/getannot.py b/app/getannot.py index 8d3cab2..55420c1 100644 --- a/app/getannot.py +++ b/app/getannot.py @@ -1,15 +1,9 @@ - - -# #https://gist.github.com/mjlavin80/186a6395c5819dbe25a8a0e001d5acfd from flask import request import requests import json -# This script demonstrates how to query annotations for a particular URL using the hypothes.is API. An API key is required. -# The end result of this script is a Python dictionary with annotation data in it. Top save to csv or other format, further parsing would be required def get_annotations(): KEY = "6879-n8AksBoSB7kYoQ3eEwzpEr3nFQEmSp3XN-0PcKL_Sik" - # URL = "https://monoskop.org/Monoskop" #a dictionary containing necessary http headers headers = { @@ -25,9 +19,9 @@ def get_annotations(): r = requests.get(search_url, headers=headers) #data is a python dictionary data = json.loads(r.text) - - # r = requests.get(search_url, headers=headers) - # data = json.loads(r.text) + server = request.host + for row in data['rows']: + row['uri']= row['uri'].replace('http://' + server+'/uploads/','') return data diff --git a/app/templates/annotations.html b/app/templates/annotations.html index f76fbc3..8af9a2c 100644 --- a/app/templates/annotations.html +++ b/app/templates/annotations.html @@ -9,7 +9,7 @@ {% for row in annot.rows %} {% if 'selector' in row.target[0] %} {%for book in books%} - {%if book.file == row.uri|replace('http://localhost:8080/uploads/','')%} + {%if book.file == row.uri%}

Book

{{book.title}}


{% endif %} diff --git a/app/templates/results_annot.html b/app/templates/results_annot.html index 9813985..9988166 100644 --- a/app/templates/results_annot.html +++ b/app/templates/results_annot.html @@ -11,7 +11,7 @@


- All annotations

+Get as PDF      All annotations

Annotations/ Extracts with:  {{name}}

diff --git a/app/views.py b/app/views.py index 3160d42..467bf12 100755 --- a/app/views.py +++ b/app/views.py @@ -109,6 +109,8 @@ def annotations(): books = db.session.query(Book).all() # books = db.session.query(Book).order_by(Book.title) # id = book.id + server = request.host + rstr=('http://' + server+'/uploads/','') annot = get_annotations() print(annot) return render_template('annotations.html', annot=annot, books=books) @@ -121,6 +123,17 @@ def annotations_pdf(): html = render_template(('annotations.html'), annot=annot) return render_pdf(HTML(string=html)) +@app.route('/myannotations.pdf') +def myannotations_pdf(): + books = db.session.query(Book).all() + name=str(request.args.get('query')) + annot = get_annotations() + res = get_annot_results(annot,name) + # Make a PDF straight from HTML in a string. + html = render_template('results_annot.html', name=name, annot=annot, res=res, books=books) + return render_pdf(HTML(string=html)) + + @app.route('/viewpdf/') def viewtestfile1_file(filename): return redirect("/static/viewer/web/viewer.html?file=%2Fuploads%2F"+urlquote(filename)) @@ -673,6 +686,7 @@ def search_annot(): res = get_annot_results(annot,name) return render_template('results_annot.html', name=name, annot=annot, res=res, books=books) + ## STACKS! @app.route('/add_to_stack/', methods=['GET', 'POST'])