aoc_mod.interactive

Script to initialize a new day for Advent of Code. This script will basically grab the input and puzzle clue from the Advent of Code website.

If user specifies a year and day, this script will create the files pertaining to that day and year.

Note: This script is being provided as a courtesy and is simply an example of using the AocMod class for a command-line utility. While the functionality is correct here and the CLI can be utilized in a user’s local install, it is recommended to perform any desired tweaks to ensure proper functionality.

Author: David Eyrich

Attributes

LOCAL_PUZZLE_FILEPATH

DEFAULT_FILE_TEMPLATE

Functions

create_solution_file(filename_in, day_path, year, day)

read in the template solution file and replace instances of "{YEAR}"

setup_challenge_day_template(aoc_mod, year, day[, ...])

set up a template folder named "challenges/{year}/day{day}" that contains

file_exists(→ str)

verify that a file exists for argparse argument

get_argument_parser(→ argparse.ArgumentParser)

create an argument parser and parse user args

interactive()

Entry-point to the aoc-mod program

Module Contents

aoc_mod.interactive.LOCAL_PUZZLE_FILEPATH = 'challenges/{YEAR}/day{DAY}'
aoc_mod.interactive.DEFAULT_FILE_TEMPLATE
aoc_mod.interactive.create_solution_file(filename_in: str, day_path: pathlib.Path, year: int, day: int)

read in the template solution file and replace instances of “{YEAR}” and “{DAY}” with the corresponding year and day arguments

Parameters:
  • filename_in (str) – path to the input file

  • day_path – path to the output directory

  • year (int) – year that was entered

  • day (int) – day that was entered

Raises:

AocModError – if an error occurs with file operations

aoc_mod.interactive.setup_challenge_day_template(aoc_mod: aoc_mod.utilities.AocMod, year: int, day: int, output_root_dir: str = '', template_path: str = '')

set up a template folder named “challenges/{year}/day{day}” that contains the puzzle input (.txt), instructions (.md) and a template solution file, if specified

Parameters:
  • year (int) – year of the AoC puzzle

  • day (int) – day of the AoC puzzle

  • output_root_dir (str, optional) – path to be prepended to the template folder, defaults to the current directory

  • template_path (str, optional) – path to a template file to use for solution code, defaults to “”

aoc_mod.interactive.file_exists(filepath: str) str

verify that a file exists for argparse argument

Parameters:

filepath (str) – path to the file

Raises:

argparse.ArgumentTypeError – raise if file doesn’t exist or filepath is not a file

Returns:

filepath, once verified

Return type:

str

aoc_mod.interactive.get_argument_parser() argparse.ArgumentParser

create an argument parser and parse user args

Returns:

parser.parse_known_args() return value

Return type:

tuple[Type[argparse.Namespace], list[str]]

aoc_mod.interactive.interactive()

Entry-point to the aoc-mod program