Last active
February 20, 2024 06:51
-
-
Save theracingapi/2b06d8dd1b328fc96eacabce48f2a172 to your computer and use it in GitHub Desktop.
Python script to pull North America meet entries and results data since tracking began in July 2023 (North America Data Add-On Required)
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 | |
from requests.auth import HTTPBasicAuth | |
import json | |
import pandas | |
from datetime import datetime, timedelta | |
import time | |
user = "USERNAME" | |
password = "PASSWORD" | |
now = datetime.now() | |
now_str = now.strftime("%Y-%m-%d") | |
def get_dates(start, end): | |
start_dt = datetime.strptime(start, "%Y-%m-%d") | |
end_dt = datetime.strptime(end, "%Y-%m-%d") | |
return pandas.date_range(start_dt, end_dt-timedelta(days=1),freq='d').strftime("%Y-%m-%d").tolist() | |
# Get range of dates for which to pull US data (tracking began July 2023) | |
dates = get_dates("2023-07-01", now_str) | |
for date in dates: | |
params={"start_date": date, "end_date": date} | |
time.sleep(0.5) | |
resp = requests.get("https://api.theracingapi.com/v1/north-america/meets", auth=HTTPBasicAuth(user, password), params=params) | |
meet_entries = [] | |
meet_results = [] | |
print(resp.json()) | |
for meet in resp.json()["meets"]: | |
time.sleep(0.5) | |
resp_entry = requests.get(f"https://api.theracingapi.com/v1/north-america/meets/{meet['meet_id']}/entries", auth=HTTPBasicAuth(user, password)) | |
meet_entries.append(resp_entry.json()) | |
time.sleep(0.5) | |
resp_results = requests.get(f"https://api.theracingapi.com/v1/north-america/meets/{meet['meet_id']}/results", auth=HTTPBasicAuth(user, password)) | |
meet_results.append(resp_results.json()) | |
# Process meet entries/results data here, e.g. build dataframe, import to db etc... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment