summaryrefslogtreecommitdiff
path: root/scraper/s2-geocode-server.py
diff options
context:
space:
mode:
Diffstat (limited to 'scraper/s2-geocode-server.py')
-rw-r--r--scraper/s2-geocode-server.py68
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)
+