-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_day.py
87 lines (60 loc) · 1.78 KB
/
new_day.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
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
86
87
from datetime import date
from pathlib import Path
from string import Template
from textwrap import dedent
from typing import Optional
import typer
solution = Template(
dedent(
"""
from pathlib import Path
from typing import TypeAlias
DataType: TypeAlias = Any
data_path = Path(__file__).parent / "data.txt"
def parse_data(text: str) -> DataType:
return text
def part1(data: DataType) -> int:
return 0
def part2(data: DataType) -> int:
return 0
if __name__ == "__main__":
data = parse_data(data_path.read_text())
print(f"Part 1 result: {part1(data)}")
print(f"Part 2 result: {part2(data)}")
"""
).lstrip()
)
test = Template(
dedent(
'''
from textwrap import dedent
from .solution import parse_data, part1, part2
test_data = parse_data(
dedent(
"""
"""
).strip()
)
def test_part1():
expected = 0
result = part1(test_data)
assert result == expected
def test_part2():
expected = 0
result = part2(test_data)
assert result == expected
'''
).lstrip()
)
def main(day_num: Optional[int] = None) -> None:
folder = make_day_folder(day_num or date.today().day)
(folder / "data.txt").touch()
(folder / "__init__.py").touch()
(folder / "solution.py").write_text(solution.substitute())
(folder / "test_solution.py").write_text(test.substitute())
def make_day_folder(day_num: int) -> Path:
folder = Path(__file__).parent / f"day{day_num}"
folder.mkdir()
return folder
if __name__ == "__main__":
typer.run(main)