forked from maneatingape/advent-of-code-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.py
30 lines (25 loc) · 963 Bytes
/
input.py
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
import pathlib
import time
import os
import glob
try:
from aocd.models import Puzzle
except ImportError:
print(f"Run `pip install advent-of-code-data` to autodownload input files")
raise SystemExit()
def download(year, day):
"""Get input and write it to input.txt inside the puzzle folder"""
puzzle = Puzzle(year=year, day=day)
output_folder = (pathlib.Path(__file__).parent / "input" / f"year{year}")
output_folder.mkdir(parents=True, exist_ok=True)
output_path = output_folder / f"day{str(day).zfill(2)}.txt"
output_path.write_text(puzzle.input_data, newline="\n")
if __name__ == "__main__":
for x in glob.glob('src/year*/day*.rs'):
path = x.split(os.sep)
year = int(path[-2].split("year")[1])
day = int(path[-1].split("day")[1][:-3])
download(year, day)
print(f"Downloaded input for year {year} day {day}")
time.sleep(1)
print("downloaded all inputs for repository")