Luke Murphy
6 years ago
8 changed files with 751 additions and 350 deletions
@ -1,61 +1,87 @@ |
|||||
from flask import request |
|
||||
import requests |
|
||||
import json |
import json |
||||
|
|
||||
|
import requests |
||||
|
|
||||
|
from flask import request |
||||
|
|
||||
|
|
||||
def get_annotations(): |
def get_annotations(): |
||||
KEY = "6879-n8AksBoSB7kYoQ3eEwzpEr3nFQEmSp3XN-0PcKL_Sik" |
# TODO(decentral1se): remove this from the source |
||||
|
KEY = "6879-n8AksBoSB7kYoQ3eEwzpEr3nFQEmSp3XN-0PcKL_Sik" |
||||
#a dictionary containing necessary http headers |
|
||||
headers = { |
# a dictionary containing necessary http headers |
||||
"Host": "hypothes.is", |
headers = { |
||||
"Accept": "application/json", |
"Host": "hypothes.is", |
||||
"Authorization": "Bearer %s" % KEY |
"Accept": "application/json", |
||||
} |
"Authorization": "Bearer %s" % KEY |
||||
|
} |
||||
base_url = "https://hypothes.is/api/search?user=xpub@hypothes.is" |
|
||||
|
base_url = "https://hypothes.is/api/search?user=xpub@hypothes.is" |
||||
search_url = "".join([base_url]) |
|
||||
|
search_url = "".join([base_url]) |
||||
r = requests.get(search_url, headers=headers) |
|
||||
#data is a python dictionary |
r = requests.get(search_url, headers=headers) |
||||
data = json.loads(r.text) |
|
||||
server = request.host |
# data is a python dictionary |
||||
for row in data['rows']: |
data = json.loads(r.text) |
||||
row['uri']= row['uri'].replace('http://' + server+'/uploads/','') |
server = request.host |
||||
return data |
|
||||
|
for row in data['rows']: |
||||
|
row['uri'] = row['uri'].replace( |
||||
def get_annot_results(annot,name): |
'http://' + server + '/uploads/', |
||||
res=[] |
'' |
||||
annot=get_annotations() |
) |
||||
for item in annot['rows']: |
|
||||
if 'selector' in item['target'][0]: |
return data |
||||
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'], 'url':item['uri']} |
|
||||
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'], 'url':item['uri']} |
|
||||
res.append(data) |
|
||||
return res |
|
||||
|
|
||||
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://' + 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://' + 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 |
|
||||
|
|
||||
|
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: |
||||
|
exact_second = item['target'][0]['selector'][2]['exact'] |
||||
|
if name in item['text'] or name in exact_second: |
||||
|
data = { |
||||
|
'text': item['text'], |
||||
|
'extract': item['target'][0]['selector'][2]['exact'], |
||||
|
'title': item['document']['title'], 'url': item['uri'] |
||||
|
} |
||||
|
res.append(data) |
||||
|
else: |
||||
|
exact_first = item['target'][0]['selector'][1]['exact'] |
||||
|
if name in item['text'] or name in exact_first: |
||||
|
data = { |
||||
|
'text': item['text'], |
||||
|
'extract': item['target'][0]['selector'][1]['exact'], |
||||
|
'title': item['document']['title'], 'url': item['uri'] |
||||
|
} |
||||
|
res.append(data) |
||||
|
return res |
||||
|
|
||||
|
|
||||
|
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://' + 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://' + 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 |
||||
|
File diff suppressed because it is too large
Loading…
Reference in new issue