File tree Expand file tree Collapse file tree 1 file changed +40
-9
lines changed Expand file tree Collapse file tree 1 file changed +40
-9
lines changed Original file line number Diff line number Diff line change 1
1
import importlib
2
2
import sys
3
+ import argparse
3
4
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
+ )
7
23
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"
9
27
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 ()
You can’t perform that action at this time.
0 commit comments