Skip to content

Commit d97e055

Browse files
committed
Get rid of hardcoded 2023 year
1 parent d7c7499 commit d97e055

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

.cruft.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"author_name": "nekeal",
88
"author_email": "[email protected]",
99
"github_username": "nekeal",
10-
"project_name": "Advent of Code 2023 - Python",
11-
"project_slug": "advent-of-code-2023",
12-
"package_name": "aoc2023",
10+
"project_name": "Advent of Code - Python",
11+
"project_slug": "advent-of-code",
12+
"package_name": "aoc",
1313
"project_short_description": "Solution of Advent of Code 2023 in Python",
1414
"python_version": "3.11+",
1515
"_python_version_specs": {

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# ⭐ Advent of Code 2023 - Python ⭐
1+
# ⭐ Advent of Code - Python ⭐
22

33
[![GitHub](https://img.shields.io/github/license/nekeal/advent-of-code-2023.svg)](https://github.com//nekeal/advent-of-code-2023/blob/master/LICENSE)
44
![GitHub Workflow Status](https://github.com/github/docs/actions/workflows/test.yml/badge.svg)
55
---
6-
**Source Code**: [https://github.com/nekeal/advent-of-code-2023](https://github.com/nekeal/advent-of-code-2023)
6+
**Source Code**: [https://github.com/nekeal/advent-of-code](https://github.com/nekeal/advent-of-code-2023)
77

88
---
99

10-
Solutions for Advent of Code 2023 in Python
10+
Solutions for Advent of Code in Python
1111

1212
## Use this project as a template
1313

pyproject.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
[tool.poetry]
2-
name = "advent-of-code-2023"
2+
name = "advent-of-code"
33
version = "0.0.1"
4-
description = "Solution of Advent of Code 2023 in Python"
4+
description = "Solution of Advent of Code in Python"
55
authors = [
66
"nekeal <[email protected]>",
77
]
88
license = "MIT"
99
readme = "README.md"
1010

11-
homepage = "https://nekeal.github.io/advent-of-code-2023"
12-
repository = "https://github.com/nekeal/advent-of-code-2023"
11+
homepage = "https://nekeal.github.io/advent-of-code"
12+
repository = "https://github.com/nekeal/advent-of-code"
1313

1414
classifiers = [
1515
"Intended Audience :: Developers",
1616
"Operating System :: OS Independent",
1717
"Programming Language :: Python",
1818
"Programming Language :: Python :: 3",
1919
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
21+
"Programming Language :: Python :: 3.13",
2022
"Topic :: Software Development :: Libraries :: Python Modules",
2123
"Typing :: Typed",
2224
]

src/aoc/main.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import importlib
22
import shutil
3+
from datetime import datetime
34
from pathlib import Path
4-
from typing import Literal, Optional
5+
from typing import Literal
56

67
import aocd
78
import pytest
@@ -14,6 +15,15 @@
1415
app = 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+
1727
def 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()
95105
def 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()
160170
def 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()
177193
def 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

Comments
 (0)