aoc.new
This commit is contained in:
parent
8197d2a3df
commit
0d2771819f
2 changed files with 50 additions and 0 deletions
49
aoc/aoc.py
49
aoc/aoc.py
|
@ -5,6 +5,7 @@ from urllib.request import Request, urlopen
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from timeit import default_timer
|
from timeit import default_timer
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
T1 = TypeVar("T1")
|
T1 = TypeVar("T1")
|
||||||
T2 = TypeVar("T2")
|
T2 = TypeVar("T2")
|
||||||
|
@ -194,6 +195,54 @@ def run_latest() -> None:
|
||||||
print(f"Time: {e_time-s_time}")
|
print(f"Time: {e_time-s_time}")
|
||||||
|
|
||||||
|
|
||||||
|
def new() -> None:
|
||||||
|
parser = ArgumentParser()
|
||||||
|
parser.add_argument("day", type=int)
|
||||||
|
parser.add_argument("--type1", "-1", default="list[int]")
|
||||||
|
parser.add_argument("--type2", "-2", default="list[int]")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
day = args.day
|
||||||
|
t1 = args.type1
|
||||||
|
t2 = args.type2
|
||||||
|
|
||||||
|
filepath = Path("aoc") / f"day{day:02d}.py"
|
||||||
|
if filepath.exists():
|
||||||
|
raise RuntimeError(f"{filepath.name} already exists")
|
||||||
|
|
||||||
|
template = f"""from __future__ import annotations
|
||||||
|
from typing import TypeAlias
|
||||||
|
|
||||||
|
from .aoc import Aoc2
|
||||||
|
|
||||||
|
P1: TypeAlias = {t1}
|
||||||
|
P2: TypeAlias = {t2}
|
||||||
|
|
||||||
|
class Day{day:02d}(Aoc2[P1, P2]):
|
||||||
|
def parseinput1(self, inpt: str) -> P1:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def parseinput2(self, inpt: str) -> P2:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def part1(self, inpt: P1) -> int:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def part2(self, inpt: P2) -> int:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
aoc = Day{day:2d}(2023,{day})
|
||||||
|
aoc.run()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()"""
|
||||||
|
|
||||||
|
with filepath.open("w") as f:
|
||||||
|
f.write(template)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
days = [
|
days = [
|
||||||
import_module(f".{file.stem}", package="aoc")
|
import_module(f".{file.stem}", package="aoc")
|
||||||
|
|
|
@ -20,3 +20,4 @@ build-backend = "poetry.core.masonry.api"
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
aoc = "aoc.aoc:main"
|
aoc = "aoc.aoc:main"
|
||||||
latest = "aoc.aoc:run_latest"
|
latest = "aoc.aoc:run_latest"
|
||||||
|
new = "aoc.aoc:new"
|
||||||
|
|
Loading…
Add table
Reference in a new issue