11import importlib
22import shutil
3+ from datetime import datetime
34from pathlib import Path
4- from typing import Literal , Optional
5+ from typing import Literal
56
67import aocd
78import pytest
1415app = typer .Typer (no_args_is_help = True )
1516
1617
18+ def get_current_aoc_year ():
19+ """
20+ Returns the current year if the current month is December (and the new AOC started)
21+ or the previous year otherwise.
22+ """
23+ now = datetime .now ()
24+ return now .year if now .month == 12 else now .year - 1
25+
26+
1727def echo (text , fg = typer .colors .GREEN ):
1828 typer .echo (
1929 typer .style (
@@ -51,9 +61,9 @@ def run_challenge(day: int, test_data: bool):
5161 module .Challenge (use_test_data = False ).run ()
5262
5363
54- def get_puzzle_object (day : int ) -> Puzzle | None :
64+ def get_puzzle_object (year : int , day : int ) -> Puzzle | None :
5565 try :
56- puzzle = Puzzle (year = 2023 , day = day )
66+ puzzle = Puzzle (year = year , day = day )
5767 return puzzle
5868 except AocdError :
5969 pass
@@ -93,7 +103,7 @@ def run(
93103
94104@app .command ()
95105def verify (
96- day : Optional [ int ] = typer .Argument (None , help = "Day of the challenge to verify." ),
106+ day : int | None = typer .Argument (None , help = "Day of the challenge to verify." ),
97107 part_one_only : bool = typer .Option (
98108 False , "--part-one" , "-1" , help = "Verify only part one of the solution."
99109 ),
@@ -159,6 +169,12 @@ def _full_validate(part: str) -> Literal["a", "b"]:
159169@app .command ()
160170def submit (
161171 day : int ,
172+ year : int = typer .Option (
173+ get_current_aoc_year (),
174+ "--year" ,
175+ "-y" ,
176+ help = "Year for which to submit the solution." ,
177+ ),
162178 part : str = typer .Argument (
163179 help = "Which part of the solution to submit. "
164180 "You can use numbers 1/2 or letters a/b."
@@ -170,12 +186,18 @@ def submit(
170186 solution = module .Challenge (use_test_data = False ).part_1 ()
171187 else :
172188 solution = module .Challenge (use_test_data = False ).part_2 ()
173- aocd .submit (solution , day = day , year = 2023 , part = validated_part )
189+ aocd .submit (solution , day = day , year = year , part = validated_part )
174190
175191
176192@app .command ()
177193def new_day (
178194 day : int = typer .Argument (help = "Day for which to create a directory." ),
195+ year : int = typer .Option (
196+ get_current_aoc_year (),
197+ "--year" ,
198+ "-y" ,
199+ help = "Year for which to get the puzzle data" ,
200+ ),
179201 force : bool = typer .Option (
180202 False ,
181203 "--force" ,
@@ -184,7 +206,7 @@ def new_day(
184206 ),
185207):
186208 """Create a directory for a new day challenge."""
187- puzzle = get_puzzle_object (day )
209+ puzzle = get_puzzle_object (year , day )
188210 if day < 1 or day > 25 :
189211 typer .echo (typer .style ("Day must be between 1 and 25." , fg = typer .colors .RED ))
190212 raise typer .Exit (1 )
0 commit comments