Last active
June 14, 2018 19:59
Star
You must be signed in to star a gist
Example of test query to triathlon statistics API
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 | |
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