Skip to content

Commit cd09f1f

Browse files
committed
fix input file typo
1 parent e1df8c8 commit cd09f1f

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

run_day.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
import importlib
22
import sys
3+
import argparse
34

4-
# if len(sys.argv) < 2:
5-
# print("Usage: python run_day.py <day>")
6-
# sys.exit(1)
5+
def main():
6+
parser = argparse.ArgumentParser(description="Run a specific Advent of Code solution.")
7+
# parser.add_argument(
8+
# "--input_file",
9+
# required=True,
10+
# type=str,
11+
# help="Path to the input file for the day's solution."
12+
# )
13+
parser.add_argument(
14+
"--year",
15+
required=True,
16+
type=int,
17+
)
18+
parser.add_argument(
19+
"--day",
20+
required=True,
21+
type=str,
22+
)
723

8-
day = sys.argv[1]
24+
args = parser.parse_args()
25+
day_zero_padded_str = str(args.day).zfill(2)
26+
input_file = f"inputs/{args.year}/{day_zero_padded_str}.dat"
927

10-
try:
11-
module = importlib.import_module(f"advent_of_code.year_2023.days.{day}")
12-
module.main() # Assumes each day's file has a `main` function
13-
except ModuleNotFoundError:
14-
print(f"Day {day} not found.")
28+
day_module = f"advent_of_code.year_{args.year}.day_{day_zero_padded_str}"
29+
print(day_module)
30+
31+
try:
32+
# Dynamically import the module for the specified day
33+
module = importlib.import_module(day_module)
34+
# Run the solution (assumes each solver module has a `main()` function)
35+
if hasattr(module, "main"):
36+
module.main(input_file)
37+
else:
38+
print("man")
39+
print(f"The module {day_module} does not have a 'main(input_file)' function.")
40+
except ModuleNotFoundError:
41+
print(f"Could not find module: {day_module}")
42+
sys.exit(1)
43+
44+
if __name__ == "__main__":
45+
main()

0 commit comments

Comments
 (0)