Created
June 3, 2019 09:14
-
-
Save oriolbx/1cb860d3550c9cc39279ed9e73470d46 to your computer and use it in GitHub Desktop.
Flask middleware to add api key on backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request | |
import requests | |
app = Flask(__name__) | |
base_url = 'https://username.carto.com/api/v2/sql' | |
api_key = 'XXXXX' | |
# just return request.params | |
@app.route('/sql', methods=['GET', 'POST']) | |
def sql2CARTO(): | |
query = request.args.get('q') | |
payload = {'q':query, 'api_key':api_key} | |
r = requests.get(base_url, params=payload) | |
print(r.url) | |
print(r.text) | |
return 'ok' | |
# serve at localhost:5000 | |
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
query = ''' | |
INSERT INTO tabla(the_geom) SELECT (cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300, 600, 900]::integer[])).the_geom | |
''' | |
r = requests.get('http://127.0.0.1:5000/sql', params={'q':query}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment