diff --git a/aoc/aoc.py b/aoc/aoc.py index baf185f..f4d5522 100644 --- a/aoc/aoc.py +++ b/aoc/aoc.py @@ -5,6 +5,7 @@ from urllib.request import Request, urlopen from html.parser import HTMLParser from importlib import import_module from timeit import default_timer +from argparse import ArgumentParser T1 = TypeVar("T1") T2 = TypeVar("T2") @@ -194,6 +195,54 @@ def run_latest() -> None: 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: days = [ import_module(f".{file.stem}", package="aoc") diff --git a/pyproject.toml b/pyproject.toml index b3a16aa..93acf34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,3 +20,4 @@ build-backend = "poetry.core.masonry.api" [tool.poetry.scripts] aoc = "aoc.aoc:main" latest = "aoc.aoc:run_latest" +new = "aoc.aoc:new"