edited getannot.py
This commit is contained in:
parent
42291a5ea4
commit
8b8c64a2d2
@ -1,17 +1,7 @@
|
||||
|
||||
|
||||
# #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():
|
||||
|
||||
|
||||
|
||||
from flask import request
|
||||
import requests
|
||||
import json
|
||||
|
||||
@ -58,16 +48,17 @@ def get_annot_results(annot,name):
|
||||
|
||||
def get_annot_book(annot,name):
|
||||
res=[]
|
||||
server = request.host
|
||||
for item in annot['rows']:
|
||||
if 'selector' in item['target'][0]:
|
||||
if len(item['target'][0]['selector'])>2:
|
||||
string=item['uri']
|
||||
if name==string.replace('http://localhost:8080/uploads/',''):
|
||||
if name==string.replace('http://' + server+'/uploads/',''):
|
||||
data={'text': item['text'],'extract':item['target'][0]['selector'][2]['exact'],'title':item['document']['title'], 'url':item['uri']}
|
||||
res.append(data)
|
||||
else:
|
||||
string=item['uri']
|
||||
if name==string.replace('http://localhost:8080/uploads/',''):
|
||||
if name==string.replace('http://' + server+'/uploads/',''):
|
||||
data={'text': item['text'],'extract':item['target'][0]['selector'][1]['exact'],'title':item['document']['title'], 'url':item['uri']}
|
||||
res.append(data)
|
||||
return res
|
||||
|
Loading…
Reference in New Issue
Block a user