Horses and people › A horse's career record
A horse's career record
Find a horse, then read its career record: runs, wins, places and the span of them. Its breeding comes in the same reply where it has been fetched.
# A horse's career record
import json, os, urllib.parse, urllib.request
BASE = "https://api.apihorseracing.com"
KEY = os.environ["AHR_KEY"]
def get(path, **params):
url = BASE + path + ("?" + urllib.parse.urlencode(params) if params else "")
req = urllib.request.Request(url, headers={"X-API-Key": KEY})
with urllib.request.urlopen(req) as r:
return json.load(r)["data"]
first = get("/v1/horses/search", name="Constitution Hill")[0]
data = get(f"/v1/horses/{first['horse_id']}")
print("Horse:", data["name"])
print("Runs:", data["career"]["runs"])
print("Wins:", data["career"]["wins"])
print("Seconds:", data["career"]["seconds"])
print("First run:", data["career"]["first_run"])
What the reply holds
- career
- Runs, wins, places and the span of them.
- pedigree
- Sire, dam and damsire, each with its own id.
When it says no
401no_key The key is missing or mistyped. Every sample reads it from AHR_KEY.403plan_needed Your plan does not reach this. The reply names the plan that does.429rate_limited Too fast. Wait the seconds in Retry-After, then try again.