Add stuff to xpplannot

master
ange 6 years ago
parent 24377874fa
commit 76044807a6

@ -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

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="svg2"
width="21.333332"
height="21.333332"
viewBox="0 0 21.333332 21.333332"
sodipodi:docname="xppl-logo.svg"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)">
<metadata
id="metadata8">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs6" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="754"
inkscape:window-height="480"
id="namedview4"
showgrid="false"
inkscape:zoom="11.062501"
inkscape:cx="10.666666"
inkscape:cy="10.666666"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="0"
inkscape:current-layer="svg2" />
<image
width="21.333332"
height="21.333332"
preserveAspectRatio="none"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gYJExABRrWV7QAAASlJREFUOMu1krGOAWEUhb870UzE
FDqFRKHTaInphUqt0mg9gIfgCeYxJGK6f8IrqFUShYxEgcjZYsNuRFhr95T3/Pfknny/SRJvyAMY
j8f4vs9yuWS73VIoFOj3+9dHcRxjZpgZ2WyWdrvNbrf7NCXpfD6rXq+rVqup2+2qWCwqTVNdNJvN
BMg5p/l8LkCj0UiSlAHwPI8oiqhWqywWC6bTKUEQ3D35eDwCYGYAZC5GmqacTicANpvN3eUwDPF9
n1arRa/X+6pwOBxUqVTUbDY1GAyUz+e1Xq/vVrgVkjQcDpXL5bRarbTf71Uul9XpdH4UYH+C8e2A
h5y/+UmSPL7AOUccx0wmE6Io+l2FW87PlHnK+ZUA5xyNRuP/KIRhiJlRKpWus7f/wQfum92c9FWQ
cQAAAABJRU5ErkJggg==
"
id="image10"
x="0"
y="0" />
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

@ -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,

@ -413,14 +413,103 @@ http://sourceforge.net/adobe/cmap/wiki/License/
</div>
</div>
<script type="application/json" class="js-hypothesis-config">
<!-- <script type="application/json" class="js-hypothesis-config">
{
"openSidebar": true,
"branding": {"appBackgroundColor": "yellow"},
"services": {"authority": "http://localhost:8080/", "grantToken": "***", "icon": "https://openclipart.org/download/272629/sihouette-animaux-10.svg"}
}</script>
<script src="//localhost:5000/embed.js"></script>
}</script> -->
<!-- <script type="text/javascript">
window.hypothesisConfig = function () {
return {
services: [{
apiUrl: 'https://hypothes.is/api/',
authority: 'partner.org',
grantToken: '***',
icon: 'https://openclipart.org/download/272629/sihouette-animaux-10.svg'
}],
};
};
</script> -->
<!-- <script src="//localhost:5000/embed.js"></script> -->
<!-- <script src= "/embed.js"></script> -->
<!-- <script type="text/javascript">
window.hypothesisConfig = function () {
return {
openSidebar: true,
showHighlights: true,
branding: {
appBackgroundColor: 'yellow',
ctaBackgroundColor: 'rgba(227, 38, 54, 1)',
ctaTextColor: '#eee',
selectionFontFamily: 'archivo narrow',
annotationFontFamily: 'archivo narrow',
accentColor: 'red'
},
services: [{
apiUrl: 'http://localhost:5000/api/',
authority: 'http://localhost:5000/',
grantToken: '6879-rwfbfodYqhBn2OK2ODnNGkzlWUa4bPCoJi2U8pgTYHg',
icon: 'https://pzwiki.wdka.nl/mw-mediadesign/images/9/9c/Xppl-logo.svg'
}],
onLayoutChange: {
width:'100'
},
sidebarAppUrl: 'http://localhost:5000/app.html'
};
};
</script> -->
<script type="text/javascript">
window.hypothesisConfig = function () {
return {
openSidebar: true,
showHighlights: true,
usernameUrl: 'localhost:8080/annotations',
branding: {
appBackgroundColor: 'yellow',
ctaBackgroundColor: 'rgba(227, 38, 54, 1)',
ctaTextColor: '#eee',
selectionFontFamily: 'archivo narrow',
annotationFontFamily: 'archivo narrow',
accentColor: 'red'
},
services: {
apiUrl: 'http://localhost:5000/api/'
// authority: 'http://localhost:5000/',
// grantToken: '6879-rwfbfodYqhBn2OK2ODnNGkzlWUa4bPCoJi2U8pgTYHg',
// icon: 'https://pzwiki.wdka.nl/mw-mediadesign/images/9/9c/Xppl-logo.svg'
},
onLayoutChange: {
width:'200',
height:'2'
},
// sidebarAppUrl: 'http://localhost:5000/app.html'
};
};
</script>
<script async id="location" src= "//localhost:5000/embed.js"></script>
<!-- <p id="location"></p> -->
<script >
document.getElementById("#location").src = window.location.hostname + ":5000/embed.js";
</script>
<!-- <script>
document.getElementById("location").src = window.location.hostname + ":5000/embed.js";
</script> -->
<!-- <script>
document.getElementById("demo").innerHTML =
"Page hostname is " + window.location.hostname;
</script>
-->
</body>
</html>

@ -1,65 +1,126 @@
{% block main %}
<h1 class="header">Annotations</h1>
<!-- create pdf from the html annotations -->
<!-- <link rel=stylesheet href="{{ url_for('static', filename='style.css') }}" /> -->
<nav><a href="{{ url_for('annotations_pdf') }}">Get as PDF</a></nav><br><br>
<script type="application/json" class="js-hypothesis-config">
{
"openSidebar": true,
"branding": {"appBackgroundColor": "yellow"},
"theme": "clean",
"enableExperimentalNewNoteButton": true
}
</script>
<script async src="http://localhost:5000/embed.js"></script>
<!-- <iframe src="/static/viewer/web/viewer.html?file=%2Fuploads%2FParatexts__Thresholds_of_Interpretation_-_Gerard_Genette.pdf" style="width:718px; height:700px;" frameborder="0"></iframe>
-->
<!-- <iframe src="https://jonudell.info/h/facet/" style="width:100%;height:100px;"></iframe> -->
<!-- <iframe src="localhost:8080/app/uploads/viewer/web/viewer.html?file=%2Fhypothesis-client.pdf"></iframe> -->
<!-- <embed src="uploads/hypothesis-client.pdf" width="50%" ></embed><br> -->
<!-- <embed src="uploads/theresa.pdf" width="50%" ></embed> -->
<!-- annotations and extracts from API -->
{% for row in annot.rows %}
row: {{row.updated}}<br>
{% if 'selector' in row.target[0] %}
{% if row.target[0].selector|length > 2%}
<a href="{{row.uri}}"><p align="right" style="font-family:archivo narrow;font-size:12;">{{row.document.title}}</p></a><br>
<div style="font-family:archivo narrow;font-size:18;">
<i>"{{row.target[0].selector[2].exact}}"</i></div><br>
{%if 'https://www.youtube.com'in row.text %}
<!-- <embed src="{{row.text}}" width="50%"></embed> -->
<a style="font-family:archivo narrow;font-size:18;color:#ff3300;" href="{{row.text}}">{{row.text}}</a><br>
{%elif '.jpg' in row.text%}
<img src="{{row.text}}" alt="{{row.document.title}}" width="400">
{%else%}
<div style="font-family:archivo narrow;font-size:18;color:#ff3300;">{{row.text}}</div><br>
{% endif %}
<hr>
{%else%}
<a href="{{row.uri}}"><p align="right" style="font-family:archivo narrow;font-size:12;">{{row.document.title}}</p></a><br>
<div style="font-family:archivo narrow;font-size:18;">
<i>"{{row.target[0].selector[1].exact}}"</i></div><br>
{%if 'https://www.youtube.com'in row.text %}
<!-- <embed src="{{row.text}}" width="50%"></embed> -->
<a style="font-family:archivo narrow;font-size:18;color:#ff3300;" href="{{row.text}}">{{row.text}}</a><br>
{%elif '.jpg' in row.text%}
<img src="{{row.text}}" alt="{{row.document.title}}" width="400">
{%else%}
<div style="font-family:archivo narrow;font-size:18;color:#ff3300;">{{row.text}}</div><br>
{% endif %}
<hr>
{% endif %}
{%else%}
<a href="{{row.uri}}"style="font-family:archivo narrow;font-size:12;">{{row.document.title}}</a><br>
<p style="font-family:archivo narrow;font-size:18;color:#ff3300;">{{row.text}}</p><br>
<hr><br>
{% endif %}
{% endfor %}
dump:
<!-- dump of the API json annotations -->
<!-- dump:
<pre>
{{dump}}
</pre>
<!-- <script src="https://gist.github.com/mjlavin80/186a6395c5819dbe25a8a0e001d5acfd.js"></script> -->
-->
<!-- <script type="application/json" class="js-hypothesis-config">
{
"openSidebar": true,
"branding": {"appBackgroundColor": "yellow"},
"enableExperimentalNewNoteButton": true
}
</script> -->
<!-- <script type="text/javascript">
window.hypothesisConfig = function () {
return {
openSidebar: true,
showHighlights: true,
usernameUrl: 'localhost:8080/annotations',
branding: {
appBackgroundColor: 'yellow',
ctaBackgroundColor: 'rgba(227, 38, 54, 1)',
ctaTextColor: '#eee',
selectionFontFamily: 'archivo narrow',
annotationFontFamily: 'archivo narrow',
accentColor: 'red'
},
services: {
apiUrl: 'http://localhost:5000/api/',
onProfileRequest: 'http://localhost:8080/',
onHelpRequest: 'http://localhost:8080/',
authority: 'http://localhost:5000/',
grantToken: '6879-rwfbfodYqhBn2OK2ODnNGkzlWUa4bPCoJi2U8pgTYHg',
icon: 'https://pzwiki.wdka.nl/mw-mediadesign/images/9/9c/Xppl-logo.svg'
},
onLayoutChange: {
width:200
},
// sidebarAppUrl: 'http://localhost:5000/app.html'
};
};
</script>
<!-- <filename> -->
<script async id="location" src="http://localhost:5000/embed.js"></script> -->
<!-- <embed type="PdfFileReader" src="http://localhost:8000/uploads/viewer.html?file=<filename>" width="300" height="300"> -->
<!-- <script async type="text/javascript" document.getElementById("location").src = window.location.hostname + ":5000/embed.js";></script> -->
{% endblock %}
<!-- <script async id="location" src= "//localhost:5000/embed.js"></script> -->
<!-- <p id="location"></p> -->
<!-- <script >
document.getElementById("#location").src = window.location.hostname + ":5000/embed.js";
</script>
-->
<!-- <script async src="http://localhost:5000/embed.js"></script> -->
<!-- <script type="application/json" class="js-hypothesis-config">
{
"showHighlights": "always",
"theme": "classic",
"branding": {"appBackgroundColor": "red"},
"onLayoutChange": {"width": 70},
"sidebarAppUrl": "https://hypothes.is/app.html"
}
</script>
<script async src="https://hypothes.is/embed.js"></script> -->
<!-- style="width:100%; height:500px;" -->
{% endblock %}
<!-- iframe {
#controlsContainer{ display:none; };
#title { display:none; };
width:100%;
height:500px;
} -->

@ -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")

@ -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)

Loading…
Cancel
Save