Skip to content

Commit

Permalink
POC: fallback to livetiming mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Jul 23, 2024
1 parent a8f7761 commit ca3775a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fastf1/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
_logger = get_logger('api')

base_url = 'https://livetiming.formula1.com'
base_url_mirror = 'https://livetiming-mirror.fastf1.dev'

headers: Dict[str, str] = {
'Host': 'livetiming.formula1.com',
'Connection': 'close',
'TE': 'identity',
'User-Agent': 'BestHTTP',
Expand Down Expand Up @@ -1699,7 +1699,14 @@ def fetch_page(path, name):
page = pages[name]
is_stream = 'jsonStream' in page
is_z = '.z.' in page

r = Cache.requests_get(base_url + path + pages[name], headers=headers)

if r.status_code >= 400:
_logger.debug(f"Falling back to livetiming mirror ({base_url_mirror})")
r = Cache.requests_get(base_url_mirror + path + pages[name],
headers=headers)

if r.status_code == 200:
raw = r.content.decode('utf-8-sig')
if is_stream:
Expand Down

0 comments on commit ca3775a

Please sign in to comment.