-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.py
More file actions
31 lines (23 loc) · 746 Bytes
/
update.py
File metadata and controls
31 lines (23 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import pathlib
import requests # type: ignore
YEAR = 2024
input_url_template = "https://adventofcode.com/{}/day/{}/input"
inputs_path = pathlib.Path(__file__).parent / "inputs"
if not inputs_path.is_dir():
inputs_path.mkdir()
for i in range(1, 26):
input_fn = f"{inputs_path}/day{i}.txt"
if os.path.exists(input_fn):
continue
input_url = input_url_template.format(YEAR, i)
with open("cookie.txt") as f:
cookie = f.read().strip()
headers = {"Cookie": cookie}
r = requests.get(input_url, headers=headers)
if r.status_code == 404:
print(f"Day {i} input not found. Breaking.")
break
r.raise_for_status()
with open(input_fn, "w") as f:
f.write(r.text)