Skip to content

Instantly share code, notes, and snippets.

@cbrannen9a
Last active June 14, 2018 19:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cbrannen9a/8a66fe5efaba4f23e93c450a9651c348 to your computer and use it in GitHub Desktop.
Example of test query to triathlon statistics API
import requests
import json
from pprint import pprint
#replace YOUR_API_KEY with your key
apikey = 'YOUR_API_KEY'
url = 'https://api.triathlon.org/v1/statistics/results?'
query = 'analysis=count_unique&target_property=event.name&group_by=event.name|program.id|program.name'
local_filename = 'test.txt'
params = {}
headers = {'content-type': 'application/json','Accept-Charset': 'UTF-8', 'apikey': apikey}
r = requests.get(url + query, headers=headers, params=params, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
data = json.load(open(local_filename))
pprint(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment