#!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') 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(): addresses = AddressBook() return jsonify({ 'entities': addresses.entities, 'lookup': addresses.lookup, }) @app.route('/api/papers', methods=['GET']) def list_papers(): lookup_keys, lines = fetch_google_sheet('citation_lookup') paper_lookup = {} for line in lines: paper_lookup[line[0]] = line return jsonify({ 'papers': paper_lookup, }) @app.route('/api/address', methods=['POST']) def add_address(): # id, title, institution_1, institution_2, institution_3, institution_4, notes locations_worksheet.insert_row([ request.form['paper_id'], request.form['title'], request.form['institution_1'], request.form['institution_2'], request.form['institution_3'], request.form['institution_4'], request.form['notes'], ]) return jsonify({ 'status': 'ok' }) if __name__=="__main__": app.run("0.0.0.0", debug=False)