diff --git a/advent_of_code/__init__.py b/advent_of_code/__init__.py new file mode 100644 index 0000000..cdd5712 --- /dev/null +++ b/advent_of_code/__init__.py @@ -0,0 +1,4 @@ +"My solutions to Advent of Code 2023" + +__author__ = "Nettika " +__version__ = "1.0.0" diff --git a/advent_of_code/__main__.py b/advent_of_code/__main__.py new file mode 100644 index 0000000..1528ab2 --- /dev/null +++ b/advent_of_code/__main__.py @@ -0,0 +1,67 @@ +import time +from argparse import ArgumentParser + +import requests + +from advent_of_code import __version__ +from advent_of_code.solver import Solver + +solvers: dict[int, Solver] = {} + + +def main(): + # Parse CLI arguments + parser = ArgumentParser(prog="Advent of Code 2023 Solver") + parser.add_argument( + "--session", + "-s", + required=True, + help="Session token", + ) + parser.add_argument( + "--day", + "-d", + required=True, + type=int, + help="Day of the month to solve", + ) + parser.add_argument( + "--version", + action="version", + version=f"%(prog)s {__version__}", + ) + args = parser.parse_args() + + # Validate day number + if args.day > 30 or args.day < 0: + print("Invalid day number") + exit(1) + + # Fetch input for the day + print(f"Fetching Day {args.day} Input...") + with requests.get( + f"https://adventofcode.com/2023/day/{args.day}/input", + cookies={"session": args.session}, + ) as response: + if not response.ok: + print("Unable to fetch input. Check your session token.") + exit(1) + input = response.text.strip() + + # Resolve solver + solver = solvers.get(args.day) + if not solver: + print(f"No solver for day {args.day}") + exit(1) + + # Execute solvers + print(f"Solving day {args.day}'s puzzle") + start = time.time() + print("Part 1 -", solver.solve_part_1(input)) + print("Part 2 -", solver.solve_part_2(input)) + end = time.time() + print(f"Solved in {end-start:,} seconds.") + + +if __name__ == "__main__": + main() diff --git a/advent_of_code/solver.py b/advent_of_code/solver.py new file mode 100644 index 0000000..2f1bdc0 --- /dev/null +++ b/advent_of_code/solver.py @@ -0,0 +1,11 @@ +from abc import ABC, abstractmethod + + +class Solver(ABC): + @abstractmethod + def solve_part_1(self, input: str) -> None: + pass + + @abstractmethod + def solve_part_2(self, input: str) -> None: + pass diff --git a/pyproject.toml b/pyproject.toml index 7a07167..1a17cc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,14 @@ [build-system] requires = ["setuptools"] +build-backend = "setuptools.build_meta" [project] -name = "advent-of-code" +name = "advent_of_code" version = "0.1.0" -dependencies = ["pytest"] +dependencies = ["requests"] + +[project.optional-dependencies] +test = ["pytest", "types-requests"] + +[project.scripts] +advent-of-code-2023 = "advent_of_code.__main__:main"