generated from xavdid/advent-of-code-python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start
executable file
·68 lines (57 loc) · 2.08 KB
/
start
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import argparse
from pathlib import Path
from misc.date_utils import current_puzzle_year, next_day
PARSER = argparse.ArgumentParser(
prog="./start", description="Scaffold a new Advent of Code solution"
)
PARSER.add_argument(
"day",
type=int,
help=(
"Which puzzle day to start, between [1,25]."
" Defaults to the next day without a folder (matching `day_N`) in that year."
),
nargs="?",
)
PARSER.add_argument("--year", default=current_puzzle_year(), help="Puzzle year")
if __name__ == "__main__":
ARGS = PARSER.parse_args()
year_dir = Path("solutions", ARGS.year)
year_dir.mkdir(parents=True, exist_ok=True)
if ARGS.day is None:
day = next_day(year_dir) + 1
else:
day = ARGS.day
if not 1 <= day <= 25:
PARSER.error(f"day {day} is not in range [1,25]")
day_dir = Path(year_dir, f"day_{day:02}")
day_dir.mkdir(parents=True, exist_ok=True)
Path(day_dir, "input.txt").touch()
Path(day_dir, "input.test.txt").touch()
notes_path = Path(day_dir, "README.md")
if not notes_path.exists():
notes_path.write_text(
"\n\n".join(
[
f"# Day {day} ({ARGS.year})",
f"`TITLE` ([prompt](https://adventofcode.com/{ARGS.year}/day/{day}))",
"Use this space for notes on the day's solution and to document what you've learned!",
"## Part 1",
"## Part 2",
"",
]
)
)
solution_path = Path(day_dir, "solution.py")
if solution_path.exists():
# if we're here, it's probably a re-run
print("ensuring input files exist")
print("skipping solution creation, file already exists")
else:
template = Path("misc/example_solution.py.tmpl").read_text()
replaced_template = template.replace("<YEAR>", ARGS.year).replace(
"<DAY>", str(day)
)
solution_path.write_text(replaced_template)
print("Created a new Solution file at", solution_path)