Created
August 3, 2017 00:18
-
-
Save stuartlynn/8788f628c85d30ccbaa20cba3e6b3f4b to your computer and use it in GitHub Desktop.
CartoQuery
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
# Run a query over the CARTO SQL api | |
def carto_query(query,username,api_key): | |
params = {'q' : query, 'format':'csv'} | |
if api_key: | |
params['api_key'] = api_key | |
url = 'https://{}.carto.com/api/v2/sql?'.format(username) + urlencode(params) | |
return pandas.read_csv(url) | |
# Take a matplotlib figure and turn it in to a response from the server | |
def mpl2img(fig): | |
canvas = FigureCanvas(fig) | |
img = StringIO() | |
canvas.print_png(img) | |
res = make_response(img.getvalue()) | |
res.headers['Content-Type'] = 'image/png' | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment