diff --git a/app/getannot.py b/app/getannot.py index 78fd698..c24b522 100644 --- a/app/getannot.py +++ b/app/getannot.py @@ -2,28 +2,37 @@ 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-GqSSbtmCoLUb8u9f6Gxh6DuScIkFKj321HSYzYZnjxc" - # here is the viewer pdf from each pdf - URL = "https://monoskop.org/Monoskop" + KEY = "6879-rwfbfodYqhBn2OK2ODnNGkzlWUa4bPCoJi2U8pgTYHg" - #a dictionary containing necessary http headers headers = { - "Host": "hypothes.is", + "Host": "xppl", "Accept": "application/json", + "Content-Type": "application/json", "Authorization": "Bearer %s" % KEY } - base_url = "https://hypothes.is/api/search" - - search_url = "".join([base_url, "?uri=", URL]) + search_url = "".join("http://localhost:5000/api/search") r = requests.get(search_url, headers=headers) - #data is a python dictionary - return json.loads(r.text) + data = json.loads(r.text) + return data + + # extract=[] + # for item in data['rows']: + # # if 'exact' in item['target'][0]['selector'][2]: + # if 'selector' in item['target'][0]: + # if len(item['target'][0]['selector']) > 2: + # extract.append('extract:' + (item['target'][0]['selector'][2]['exact'])) + # extract.append('annotation:' + item['text']) + # extract.append ('-----------') + # else: + # extract.append('annotation:' + item['text']) + # extract.append ('-----------') + # return extract + + + + diff --git a/app/static/img/xppl-logo.svg b/app/static/img/xppl-logo.svg new file mode 100755 index 0000000..0286d62 --- /dev/null +++ b/app/static/img/xppl-logo.svg @@ -0,0 +1,70 @@ + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/app/static/viewer/web/viewer.css b/app/static/viewer/web/viewer.css index 153c93b..3a4212d 100755 --- a/app/static/viewer/web/viewer.css +++ b/app/static/viewer/web/viewer.css @@ -178,7 +178,7 @@ html { height: 100%; /* Font size is needed to make the activity bar the correct size. */ - font-size: 10px; + font-size: 18px; } body { @@ -1613,15 +1613,15 @@ html[dir='rtl'] #documentPropertiesOverlay .row > * { background: none repeat scroll 0 0 yellow; } #PDFBug .stats { - font-family: courier; - font-size: 10px; + font-family: Archivo Narrow; + font-size: 18px; white-space: pre; } #PDFBug .stats .title { font-weight: bold; } #PDFBug table { - font-size: 10px; + font-size: 18px; } #viewer.textLayer-visible .textLayer > div, diff --git a/app/static/viewer/web/viewer.html b/app/static/viewer/web/viewer.html index 28f3a0b..9d75574 100755 --- a/app/static/viewer/web/viewer.html +++ b/app/static/viewer/web/viewer.html @@ -413,14 +413,103 @@ http://sourceforge.net/adobe/cmap/wiki/License/ - --> + + + + + + + + + + + + + + + + + + + + diff --git a/app/templates/annotations.html b/app/templates/annotations.html index ab44fcb..d707af2 100644 --- a/app/templates/annotations.html +++ b/app/templates/annotations.html @@ -1,65 +1,126 @@ - {% block main %}

Annotations

+ + +

- - + - - - - - - + {% for row in annot.rows %} -row: {{row.updated}}
+ {% if 'selector' in row.target[0] %} + {% if row.target[0].selector|length > 2%} +

{{row.document.title}}


+ +
+ "{{row.target[0].selector[2].exact}}"

+ + {%if 'https://www.youtube.com'in row.text %} + + {{row.text}}
+ {%elif '.jpg' in row.text%} + {{row.document.title}} + {%else%} +
{{row.text}}

+ {% endif %} +
+ + {%else%} +

{{row.document.title}}


+ +
+ "{{row.target[0].selector[1].exact}}"

+ + {%if 'https://www.youtube.com'in row.text %} + + + {{row.text}}
+ {%elif '.jpg' in row.text%} + {{row.document.title}} + {%else%} +
{{row.text}}

+ {% endif %} + +
+ {% endif %} + {%else%} + {{row.document.title}}
+

{{row.text}}


+

+ {% endif %} {% endfor %} -dump: + + + --> + + + + + + --> - + -{% endblock %} + + + + - - +{% endblock %} + + - diff --git a/app/test.txt b/app/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/app/views.py b/app/views.py index 789f23c..4f84bf8 100755 --- a/app/views.py +++ b/app/views.py @@ -7,6 +7,7 @@ This file creates your application. from app import app, db, socketio, DOMAIN from flask import Flask, Response, session, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort +from flask_weasyprint import HTML, render_pdf import json import os from sqlalchemy.sql.expression import func, select @@ -21,8 +22,6 @@ import datetime import time import autocomplete import sys - - from werkzeug.utils import secure_filename # import sqlite3 @@ -332,7 +331,6 @@ def edit_stack_by_id(id): @app.route('/books', methods= ['POST','GET']) def show_books(): autocomplete.load() #Train markov model once, for autocomplete in search - books = db.session.query(Book).all() search = SearchForm(request.form) if request.method == 'POST': @@ -355,6 +353,9 @@ def search_results(searchtype, query): if searchtype== 'All': results=Book.query.whoosh_search(query).all() + # if searchtype== 'Annotation': + # results=Book.query.filter(Book.category.contains(query)).all() + if not results: upload_form = UploadForm(title= query, author='') return render_template('red_link.html', form=upload_form, title=query) @@ -463,6 +464,7 @@ def send_text_file(file_name): file_dot_text = file_name + '.txt' return app.send_static_file(file_dot_text) +# annotations @app.route('/annotations') def annotations(): """Render annotations page.""" @@ -471,6 +473,15 @@ def annotations(): dump = json.dumps(annot, indent=2) return render_template('annotations.html', annot=annot, dump=dump) +# PDF from annotations +@app.route('/annotations.pdf') +def annotations_pdf(): + annot = get_annotations() + # Make a PDF straight from HTML in a string. + html = render_template(('annotations.html'), annot=annot) + return render_pdf(HTML(string=html)) + + @app.after_request def add_header(response): """ @@ -511,5 +522,5 @@ def new_message(message): if __name__ == '__main__': - socketio.run(app) - #app.run(debug=True,host="0.0.0.0",port="8080") + # socketio.run(app) + app.run(debug=True,host="0.0.0.0",port="8080") diff --git a/run.py b/run.py index 2ba00ff..3630a9b 100755 --- a/run.py +++ b/run.py @@ -1,4 +1,4 @@ #! /usr/bin/env python from app import app, socketio -socketio.run(app) -#app.run(debug=True,host="0.0.0.0",port=8080) +# socketio.run(app) +app.run(debug=True,host="0.0.0.0",port=8080)