Allow helpers to be imported without cookies

This commit is contained in:
Luke Hubmayer-Werner 2022-12-10 16:35:42 +10:30
parent b6c9f3f016
commit 5ab619d420
1 changed files with 17 additions and 13 deletions

View File

@ -1,14 +1,16 @@
from numpy.typing import ArrayLike from numpy.typing import ArrayLike
import browser_cookie3
import datetime
import numpy as np import numpy as np
import re import re
import requests import requests
today = datetime.date.today() try:
day = today.day import datetime
year = today.year today = datetime.date.today()
def download_input(day: int = day): day = today.day
year = today.year
import browser_cookie3
def download_input(day: int = day):
filename = f'input/{day:02}' filename = f'input/{day:02}'
r = requests.get(f"https://adventofcode.com/{year}/day/{day}/input", cookies=browser_cookie3.firefox()) r = requests.get(f"https://adventofcode.com/{year}/day/{day}/input", cookies=browser_cookie3.firefox())
if r.status_code != 200: if r.status_code != 200:
@ -16,6 +18,8 @@ def download_input(day: int = day):
else: else:
with open(filename,'w') as f: with open(filename,'w') as f:
f.write(r.text) f.write(r.text)
except ModuleNotFoundError as mod:
print(f'{mod.args[0]}, automatic input fetching will not work.')
numbers_pattern = re.compile(r'((?:(?<!\d)-)?\d+)') numbers_pattern = re.compile(r'((?:(?<!\d)-)?\d+)')