Skip to content

Instantly share code, notes, and snippets.

@danhammer
Created October 25, 2013 19:51
Show Gist options
  • Save danhammer/7160839 to your computer and use it in GitHub Desktop.
Save danhammer/7160839 to your computer and use it in GitHub Desktop.
A very quick example of how to construct the query that will eventually be linked to on the country pages.
import requests
def construct_query(iso, fmt = 'shp'):
# Builds the API call to download FORMA in various formats Other
# acceptable formats are 'csv', 'GeoJSON', 'JSON', 'kml', or 'svg'
base = "http://wri-01.cartodb.com/api/v2"
var = "x,y,date_array"
sql = "SELECT %s FROM gfw2_forma WHERE iso = '{%s}'" % (var, iso)
query = "%s/sql?format=%s&q=%s" % (base, fmt, sql)
# return the result. do something with it, depending on format.
return requests.get(query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment