feat: handle error when fetching file for future day
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import datetime
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -15,8 +16,21 @@ def download(year: int, day: int, session_token: str | None) -> bytes:
|
|||||||
response = requests.get(url, cookies=cookies)
|
response = requests.get(url, cookies=cookies)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
|
status = response.status_code
|
||||||
|
|
||||||
|
# https://stackoverflow.com/a/39079819/11286805
|
||||||
|
local_tz = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
|
||||||
|
|
||||||
|
now = datetime.datetime.now(local_tz)
|
||||||
|
release = datetime.datetime(year, 12, day, 5, tzinfo=datetime.UTC)
|
||||||
|
|
||||||
|
if now < release:
|
||||||
|
raise exceptions.AocError(
|
||||||
|
f"unreleased input file {year}/{day:02} (http:{status})"
|
||||||
|
)
|
||||||
|
|
||||||
raise exceptions.AocError(
|
raise exceptions.AocError(
|
||||||
f"failed to fetch input file {year}/{day:02} (http:{response.status_code})"
|
f"failed to fetch input file {year}/{day:02} (http:{status})"
|
||||||
" - is AOC_SESSION_TOKEN environment variable set?"
|
" - is AOC_SESSION_TOKEN environment variable set?"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user