Repository: wimglenn/advent-of-code-data

Issue:
"Part" in filename causes introspection of day failure
./AoC2024/day14.py works fine, but none of ./AoC2024/day14part2.py ./AoC2024/day14_part2.py ./AoC2024/day14p2.py work.

```Traceback (most recent call last):
  File "D:\repos\AoC2024\day14_p2.py", line 1, in <module>
    from aocd import data
  File "C:\Program Files\Python312\Lib\site-packages\aocd\__init__.py", line 48, in __getattr__
    day, year = get_day_and_year()
                ^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\aocd\get.py", line 201, in get_day_and_year
    raise giveup("Failed introspection of day")
aocd.exceptions.AocdError: Failed introspection of day
```

it'd be great if this was supported for people who want to keep part 1 and part 2 separate and clearly labelled, either because the approaches are different or because they're only doing one part in python.

Discussion:

Patch:
diff --git a/aocd/get.py b/aocd/get.py
index 9579096..02e638a 100644
--- a/aocd/get.py
+++ b/aocd/get.py
@@ -133,6 +133,7 @@ def get_day_and_year() -> tuple[int, int | None]:
         filename = frame[0]
         linetxt = frame[-1] or ""
         basename = os.path.basename(filename)
+        basename = basename.split("part")[0]
         reasons_to_skip_frame = [
             not re.search(pattern_day, basename),  # no digits in filename
             filename == __file__,  # here


Test patch:
diff --git a/tests/test_date_introspection.py b/tests/test_date_introspection.py
index 8535351..2956821 100644
--- a/tests/test_date_introspection.py
+++ b/tests/test_date_introspection.py
@@ -72,3 +72,11 @@ def test_no_numbers_in_py_filename_but_date_in_abspath(mocker):
     day, year = get_day_and_year()
     assert day == 2
     assert year == 2022
+
+
+def test_get_day_and_year_separate_part2_filename(mocker):
+    stack = [("AoC2024/day14part2.py", 1, "<test>", "from aocd import data")]
+    mocker.patch("aocd.get.traceback.extract_stack", return_value=stack)
+    day, year = get_day_and_year()
+    assert day == 14
+    assert year == 2024