-
Notifications
You must be signed in to change notification settings - Fork 3
/
start
executable file
·85 lines (74 loc) · 2.51 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
import argparse
from datetime import date
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 = ARGS.year
year_dir = Path("solutions", 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()
Path(day_dir, "README.md").write_text(
"\n".join(
[
f"# {year} Day {day}",
"",
f"For a full explanation of this code, check out https://advent-of-code.xavd.id/writeups/{year}/day/{day}",
]
)
)
writeup_folder = Path("blog", "src", "content", "writeups", str(year), str(day))
writeup_folder.mkdir(parents=True, exist_ok=True)
notes_path = writeup_folder / "index.md"
if not notes_path.exists():
notes_path.write_text(
"\n".join(
[
"---",
f"year: {year}",
f"day: {day}",
f"slug: {year}/day/{day}",
'title: "TKTK"',
"# concepts: []",
'# pub_date: "TBD"',
"---",
"",
"## 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("skipping solution creation, file already exists")
else:
template = Path("misc/example_solution.py.tmpl").read_text()
replaced_template = template.replace("<YEAR>", year).replace("<DAY>", str(day))
solution_path.write_text(replaced_template)