diff options
Diffstat (limited to 'scraper/s2-geocode-server.py')
| -rw-r--r-- | scraper/s2-geocode-server.py | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/scraper/s2-geocode-server.py b/scraper/s2-geocode-server.py index 1c624a52..0b1b0937 100644 --- a/scraper/s2-geocode-server.py +++ b/scraper/s2-geocode-server.py @@ -13,15 +13,19 @@ load_dotenv() from util import * -app = Flask(__name__, static_url_path="/reports/", static_folder="reports") +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('reports/geocode-papers.html') + 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 list the papers -# route to get all the un-geocoded citations for a paper # route to get all the manually geocoded IDs (to dedupe) # route to add a geocoding for a paper @@ -36,23 +40,29 @@ def list_locations(): @app.route('/api/papers', methods=['GET']) def list_papers(): lookup_keys, lines = fetch_google_sheet('citation_lookup') - lookup = {} + paper_lookup = {} for line in lines: - lookup[line[0]] = line - return jsonify({ - 'papers': papers, - }) - -@app.route('/api/papers/:citation/', methods=['GET']) -def list_citations(citation): + paper_lookup[line[0]] = line return jsonify({ + 'papers': paper_lookup, }) -@app.route('/api/geocode', methods=['POST']) -def geocode_paper(): +@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) + app.run("0.0.0.0", debug=False) |
