1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#!python
import os
import sys
import json
import time
import argparse
from datetime import datetime
from flask import Flask, request, render_template, jsonify
from dotenv import load_dotenv
load_dotenv()
from util import *
locations_worksheet = fetch_worksheet('paper_locations')
verifications_worksheet = fetch_worksheet('verifications')
paper_lookup = fetch_google_lookup('citation_lookup')
addresses = AddressBook()
app = Flask(__name__, static_url_path="/reports", static_folder=os.path.abspath("reports"))
# static api route
@app.route('/', methods=['GET'])
def index():
return app.send_static_file('geocode_papers.html')
@app.errorhandler(404)
def page_not_found(e):
return app.send_static_file('geocode_papers.html')
# route to get all the manually geocoded IDs (to dedupe)
# route to add a geocoding for a paper
@app.route('/api/institutions', methods=['GET'])
def list_locations():
return jsonify({
'entities': addresses.entities,
'lookup': addresses.lookup,
})
@app.route('/api/papers', methods=['GET'])
def list_papers():
return jsonify({
'papers': paper_lookup,
})
@app.route('/api/address/<sha256>', methods=['GET'])
def find_address(sha256):
worksheet = fetch_worksheet('paper_locations')
try:
cell = worksheet.find(sha256)
except:
return jsonify({
'error': 'no_match'
})
if cell and cell.row:
keys = worksheet.row_values(1)
values_list = worksheet.row_values(cell.row)
lookup = {}
for key, value in zip(keys, values_list):
lookup[key] = value
return jsonify({
'paper': lookup,
})
else:
return jsonify({
'error': 'no_match'
})
@app.route('/api/address/add', methods=['POST'])
def add_address():
form = request.get_json()
print(form)
# id, title, institution_1, institution_2, institution_3, institution_4, notes
locations_worksheet.append_row([
form['paper_id'],
form['title'],
form['institution_1'],
form['institution_1_vetting'],
form['institution_2'],
form['institution_2_vetting'],
form['institution_3'],
form['institution_3_vetting'],
form['institution_4'],
form['institution_4_vetting'],
form['notes'],
])
return jsonify({
'status': 'ok'
})
@app.route('/api/verify/<sha256>', methods=['GET'])
def find_verification(sha256):
worksheet = fetch_worksheet('verifications')
try:
cell = worksheet.find(sha256)
except:
return jsonify({
'error': 'no_match'
})
if cell and cell.row:
keys = worksheet.row_values(1)
values_list = worksheet.row_values(cell.row)
lookup = {}
for key, value in zip(keys, values_list):
lookup[key] = value
return jsonify({
'paper': lookup,
})
else:
return jsonify({
'error': 'no_match'
})
@app.route('/api/verify/add', methods=['POST'])
def add_verifications():
form = request.get_json()
print(form)
keys = verifications_worksheet.row_values(1)
row = [ form[key] if key in form else '' for key in keys ]
verifications_worksheet.append_row(row)
return jsonify({
'status': 'ok'
})
if __name__=="__main__":
app.run("0.0.0.0", port=7727, debug=False)
|