events.py script is the foundation of the data collection pipeline. It fetches the race calendar for each season and creates the directory structure for storing race data.
Script Overview
Location:~/workspace/source/events.py
The events script:
- Fetches the race calendar for specified seasons
- Creates year and race directories
- Saves event metadata for each race
- Stores the complete season calendar
API Endpoint
The script uses the Ergast API races endpoint:Key Functions
Race Name Slugification
Converts race names to URL-friendly folder names:- “Belgian Grand Prix” →
belgian-grand-prix - “Monaco Grand Prix” →
monaco-grand-prix
Directory Creation
Rate-Limited Fetching
The script sleeps for 0.3 seconds between requests to stay within the 4 requests/second limit.
Main Process
The main function iterates through seasons and processes each race:Output Structure
events.json (Season Calendar)
Stored at:{year}/events.json
event_info.json (Individual Race)
Stored at:{year}/{race-name}/event_info.json
Usage Example
To fetch events for multiple seasons:main() function:
Next Steps
After collecting events data, you can fetch:Race Results
Fetch finishing positions and race outcomes
Qualifying
Collect qualifying session results