diff --git a/download.py b/download.py index 6dde19f..84132b9 100644 --- a/download.py +++ b/download.py @@ -76,9 +76,11 @@ def get_puzzle_source(date: PuzzleDate, token: str) -> str: return res.text + def build_cookies(token: str) -> dict[str, str]: return {"session": token} + def extract_sample_inputs(puzzle_source: str) -> List[str]: LOG.debug("Extracting puzzle inputs from puzzle source") souped_puzzle_source = bs4.BeautifulSoup(puzzle_source, "html.parser") @@ -138,7 +140,9 @@ def save_sample_inputs(sample_inputs: Iterable[str], output_dir: pathlib.Path): LOG.info(f"Downloaded {num_inputs} sample input(s) successfully") -def download_sample_inputs(date: PuzzleDate, token: str, output_dir: pathlib.Path, *, interactive): +def download_sample_inputs( + date: PuzzleDate, token: str, output_dir: pathlib.Path, *, interactive +): inputs = find_sample_inputs(date, token) if interactive: inputs = interactively_filter_sample_inputs(inputs) @@ -161,6 +165,7 @@ def download_input(date: PuzzleDate, token: str, output_dir: pathlib.Path): puzzle_input = fetch_input(date, token) data_to_write = ensure_ends_with(puzzle_input, os.linesep) path = output_dir / "input.txt" + with open(path, "w") as input_file: input_file.write(data_to_write) @@ -296,7 +301,9 @@ def main( try: step = "download sample inputs" if not input_only: - download_sample_inputs(date_to_fetch, token, output_dir, interactive=interactive) + download_sample_inputs( + date_to_fetch, token, output_dir, interactive=interactive + ) step = "download input" download_input(date_to_fetch, token, output_dir) except requests.exceptions.HTTPError as err: