Some style change I made a year ago
parent
4eb63d40b0
commit
a0c01e2a31
11
download.py
11
download.py
|
@ -76,9 +76,11 @@ def get_puzzle_source(date: PuzzleDate, token: str) -> str:
|
||||||
|
|
||||||
return res.text
|
return res.text
|
||||||
|
|
||||||
|
|
||||||
def build_cookies(token: str) -> dict[str, str]:
|
def build_cookies(token: str) -> dict[str, str]:
|
||||||
return {"session": token}
|
return {"session": token}
|
||||||
|
|
||||||
|
|
||||||
def extract_sample_inputs(puzzle_source: str) -> List[str]:
|
def extract_sample_inputs(puzzle_source: str) -> List[str]:
|
||||||
LOG.debug("Extracting puzzle inputs from puzzle source")
|
LOG.debug("Extracting puzzle inputs from puzzle source")
|
||||||
souped_puzzle_source = bs4.BeautifulSoup(puzzle_source, "html.parser")
|
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")
|
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)
|
inputs = find_sample_inputs(date, token)
|
||||||
if interactive:
|
if interactive:
|
||||||
inputs = interactively_filter_sample_inputs(inputs)
|
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)
|
puzzle_input = fetch_input(date, token)
|
||||||
data_to_write = ensure_ends_with(puzzle_input, os.linesep)
|
data_to_write = ensure_ends_with(puzzle_input, os.linesep)
|
||||||
path = output_dir / "input.txt"
|
path = output_dir / "input.txt"
|
||||||
|
|
||||||
with open(path, "w") as input_file:
|
with open(path, "w") as input_file:
|
||||||
input_file.write(data_to_write)
|
input_file.write(data_to_write)
|
||||||
|
|
||||||
|
@ -296,7 +301,9 @@ def main(
|
||||||
try:
|
try:
|
||||||
step = "download sample inputs"
|
step = "download sample inputs"
|
||||||
if not input_only:
|
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"
|
step = "download input"
|
||||||
download_input(date_to_fetch, token, output_dir)
|
download_input(date_to_fetch, token, output_dir)
|
||||||
except requests.exceptions.HTTPError as err:
|
except requests.exceptions.HTTPError as err:
|
||||||
|
|
Loading…
Reference in New Issue