diff options
| author | jules@lens <julescarbon@gmail.com> | 2019-02-13 02:02:11 +0100 |
|---|---|---|
| committer | jules@lens <julescarbon@gmail.com> | 2019-02-13 02:02:11 +0100 |
| commit | 857a8a5f13fa63e7cbc56bfee0361c8c02860424 (patch) | |
| tree | caf41529595dd05ca0808a9fcf5739613df3438c /scraper/s2-geocode-server.py | |
| parent | 84500c8a1e4e7ef267d71fdf8ad5a52fb33b2cb5 (diff) | |
| parent | dc7d9cbba842472efb33186e97ee55751e4d50ca (diff) | |
Merge branch 'master' of asdf.us:megapixels_dev
Diffstat (limited to 'scraper/s2-geocode-server.py')
| -rw-r--r-- | scraper/s2-geocode-server.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/scraper/s2-geocode-server.py b/scraper/s2-geocode-server.py new file mode 100644 index 00000000..0b1b0937 --- /dev/null +++ b/scraper/s2-geocode-server.py @@ -0,0 +1,68 @@ +#!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) + |
