I host glance on one of my home servers. As a big F1 fan, I was excited to see that the community had added a F1 integration, but was disappointed with the rigidity of the API it uses.
I ran into the following issues with the API that this repository solves:
- Times were shown in UTC, not specific to a users timezone.
- API calls were slow and there was no smart caching, slowing down my Glance.
- Lack of control over data fields like team name. It shows lengthy official team names like "Mercedes AMG Petronas F1 Team" instead of just "Mercedes"
- Lacking detail. For instance, I wanted a track map, lap record holder, previous winners when it displayed the next race.
- Lack of dynamic control over event time. While you can select what event to have a countdown to (IE race vs. qualifying), you have to manually specify this instead of using time analysis to show the next event that hasn't passed.
As a solution, I created 4 API endpoints that allow me full control over what I fetch, as well as caching behaviour. Across each endpoint, I utilize smart caching that only refreshes the underlying API data a few hours after the race is over, preventing unnecessary loading when results have not changed.
The 4 end points are:
- Next race. This features details such as circuit name, lap record holder, and countdown to the race.
- Driver championship. This cleans up the naming of each driver and adds a nice nationality flag for each driver.
- Constructors championship. Cleans up team names to a simplified form and adds home country flag for each team.
- Track map. This generates an SVG of the current track. It relies on positioning data from a prior years event at the same track.
I really enjoyed the theme and style of the community widgets by @abaza738, so I largely use their theming and design, I just change the underlying API to achieve more custom results.
See the /Glance Widgets/ folder for a list of Glance widgets you can integrate into your Glance set up. For more info on how to add these, so Glance documentation
This repo uses docker compose to install. Verify that you are up to date. Below is an example compose file.
version: "3.9"
services:
f1_api:
container_name: f1_api
image: skyallinott/f1_api:latest
environment:
- TIMEZONE=America/Edmonton # Specify your timezone.
- TRACK_COLOUR=#e5d486 # Specify desired track map color
- EVENT_DETAIL=main # Optional. main tracks qualis and races (inc. sprints), race tracks races.
ports:
- 4463:4463
restart: unless-stoppedTo integrate with your glance set up (to install glance, see their documentation), add the f1_next_race.yml, f1_drivers_championship.yml, and f1_constructors_championship.yml to your glance config, making sure to replace the {LOCAL_IP} with your devices IP, as well as updating the ports if needed.
On the left below is a possible configuration using this custom API. On the right is a configuration using the default API used in the community widget.
The largest difference is localized time zones, track map, added track details, and general tidying up of the championship orders.
glance-F1/
├── API/
│ ├── main.py # FastAPI application entry point
│ ├── requirements.txt # Python dependencies
│ ├── Dockerfile # Container build instructions
│ └── API_Endpoints/
│ ├── constructors_cleaner.py
│ ├── current_race_cleaner.py
│ ├── drivers_cleaner.py
│ └── map/
│ ├── map_generator.py # Track SVG generation
│ └── router.py # Map endpoint logic
├── Glance Widgets/ # YAML files for Glance integration
└── docker-compose.yaml # Local development compose file

