diff options
Diffstat (limited to 'scraper/s2-geocode-server.py')
| -rw-r--r-- | scraper/s2-geocode-server.py | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/scraper/s2-geocode-server.py b/scraper/s2-geocode-server.py index 9d824443..3aeda881 100644 --- a/scraper/s2-geocode-server.py +++ b/scraper/s2-geocode-server.py @@ -13,9 +13,6 @@ 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")) @@ -41,6 +38,7 @@ def list_locations(): @app.route('/api/papers', methods=['GET']) def list_papers(): + paper_lookup = fetch_google_lookup('citation_lookup') return jsonify({ 'papers': paper_lookup, }) @@ -73,6 +71,7 @@ def add_address(): form = request.get_json() print(form) # id, title, institution_1, institution_2, institution_3, institution_4, notes + locations_worksheet = fetch_worksheet('paper_locations') locations_worksheet.append_row([ form['paper_id'], form['title'], @@ -90,6 +89,23 @@ def add_address(): 'status': 'ok' }) +@app.route('/api/verifications', methods=['GET']) +def list_verifications(): + return jsonify({ + 'verifications': fetch_google_lookup('verifications', item_key='paper_id'), + }) + +@app.route('/api/verifications/<dataset>', methods=['GET']) +def list_dataset_verifications(dataset): + rows = fetch_google_sheet_objects('verifications') + verifications = {} + for row in rows: + if row['dataset'] == dataset: + verifications[row['paper_id']] = row + return jsonify({ + dataset: verifications, + }) + @app.route('/api/verify/<sha256>', methods=['GET']) def find_verification(sha256): worksheet = fetch_worksheet('verifications') @@ -114,12 +130,12 @@ def find_verification(sha256): }) @app.route('/api/verify/add', methods=['POST']) -def add_verifications(): +def add_verification(): 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) + update_or_append_worksheet('verifications', form) + if form['isUnknown']: + update_or_append_worksheet('paper_locations', form) return jsonify({ 'status': 'ok' }) |
