forked from XPUB/XPPL
changes to annotations
parent
6205fc7272
commit
d21cfdaafc
@ -1,38 +1,75 @@
|
|||||||
#https://gist.github.com/mjlavin80/186a6395c5819dbe25a8a0e001d5acfd
|
|
||||||
|
|
||||||
|
# #https://gist.github.com/mjlavin80/186a6395c5819dbe25a8a0e001d5acfd
|
||||||
|
# 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():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import json
|
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():
|
def get_annotations():
|
||||||
KEY = "6879-rwfbfodYqhBn2OK2ODnNGkzlWUa4bPCoJi2U8pgTYHg"
|
KEY = "6879-n8AksBoSB7kYoQ3eEwzpEr3nFQEmSp3XN-0PcKL_Sik"
|
||||||
|
# URL = "https://monoskop.org/Monoskop"
|
||||||
|
|
||||||
|
#a dictionary containing necessary http headers
|
||||||
headers = {
|
headers = {
|
||||||
"Host": "xppl",
|
"Host": "hypothes.is",
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Authorization": "Bearer %s" % KEY
|
"Authorization": "Bearer %s" % KEY
|
||||||
}
|
}
|
||||||
|
|
||||||
search_url = "".join("http://localhost:5000/api/search")
|
base_url = "https://hypothes.is/api/search?user=xpub@hypothes.is"
|
||||||
|
|
||||||
|
search_url = "".join([base_url])
|
||||||
|
|
||||||
r = requests.get(search_url, headers=headers)
|
r = requests.get(search_url, headers=headers)
|
||||||
|
#data is a python dictionary
|
||||||
data = json.loads(r.text)
|
data = json.loads(r.text)
|
||||||
return data
|
|
||||||
|
|
||||||
# extract=[]
|
# r = requests.get(search_url, headers=headers)
|
||||||
# for item in data['rows']:
|
# data = json.loads(r.text)
|
||||||
# # if 'exact' in item['target'][0]['selector'][2]:
|
return data
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_annot_results(annot,name):
|
||||||
|
res=[]
|
||||||
|
annot=get_annotations()
|
||||||
|
for item in annot['rows']:
|
||||||
|
if 'selector' in item['target'][0]:
|
||||||
|
if len(item['target'][0]['selector'])>2:
|
||||||
|
if name in item['text'] or name in item['target'][0]['selector'][2]['exact']:
|
||||||
|
data={'text': item['text'],'extract':item['target'][0]['selector'][2]['exact'],'title':item['document']['title']}
|
||||||
|
res.append(data)
|
||||||
|
else:
|
||||||
|
if name in item['text'] or name in item['target'][0]['selector'][1]['exact']:
|
||||||
|
data={'text': item['text'],'extract':item['target'][0]['selector'][1]['exact'],'title':item['document']['title']}
|
||||||
|
res.append(data)
|
||||||
|
return res
|
||||||
|
|
||||||
|
def get_annot_book(annot,name):
|
||||||
|
bannot=[]
|
||||||
|
annot=get_annotations()
|
||||||
|
for item in annot['rows']:
|
||||||
|
if 'selector' in item['target'][0]:
|
||||||
|
if len(item['target'][0]['selector'])>2:
|
||||||
|
if name==item['uri']:
|
||||||
|
data={'text': item['text'],'extract':item['target'][0]['selector'][2]['exact'],'title':item['document']['title']}
|
||||||
|
bannot.append(data)
|
||||||
|
else:
|
||||||
|
if name in item['uri']:
|
||||||
|
data={'text': item['text'],'extract':item['target'][0]['selector'][1]['exact'],'title':item['document']['title']}
|
||||||
|
bannot.append(data)
|
||||||
|
return bannot
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block main %}
|
||||||
|
<br><br><br>
|
||||||
|
<!-- <nav><a href="{{ url_for('mybook_pdf') }}">Get as PDF</a></nav> -->
|
||||||
|
|
||||||
|
<form style="float:left;" action="/search_annot" method="GET">
|
||||||
|
Browse annotations:<br>
|
||||||
|
<div style="float:left;" class="search">
|
||||||
|
<input type="text" name="query" value="{{name}}">
|
||||||
|
</div>
|
||||||
|
<input type="submit" value="Submit"></input>
|
||||||
|
</form>
|
||||||
|
<br><br><br><br><br>
|
||||||
|
|
||||||
|
<a href="/annotations" style="font-family:archivo narrow;font-size:18px; float:center;"> All</a>
|
||||||
|
|
||||||
|
|
||||||
|
<br><br><br><br>
|
||||||
|
{% for row in res %}
|
||||||
|
{%for book in books%}
|
||||||
|
{%if book.file == row.uri%}
|
||||||
|
<a href="books/{{book.id}}"><p align="right" style="font-family:archivo narrow;font-size:18px;">{{book.title}}</p></a><br>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<p align="right" style="font-family:archivo narrow;font-size:14px;">{{row.title}}</p><br>
|
||||||
|
|
||||||
|
<p style="font-family:archivo narrow;font-size:8px;">Extracts:</p>
|
||||||
|
<div style="font-family:archivo narrow;font-family:archivo narrow;font-size:18px;">
|
||||||
|
<i>"{{ row.extract }}"</i></div><br>
|
||||||
|
|
||||||
|
<p style="font-family:archivo narrow;font-size:8px;color:#ff3300;">Annotations:</p>
|
||||||
|
{%if 'https://www.youtube.com'in row.text %}
|
||||||
|
<a style="font-family:archivo narrow;font-size:18px;color:#ff3300;" href="{{row.text}}">{{row.text}}</a><br>
|
||||||
|
<hr>
|
||||||
|
{%elif '.jpg' in row.text%}
|
||||||
|
<img src="{{row.text}}" alt="" width="400">
|
||||||
|
<hr>
|
||||||
|
{%else%}
|
||||||
|
<div style="font-family:archivo narrow;font-size:18px;color:#ff3300;">{{row.text}}</div><br>
|
||||||
|
<hr>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue