aoc_mod.utilities¶
Utility functionality and AocMod class definitions
Attributes¶
Exceptions¶
General exception for an AOC_MOD library error |
Classes¶
Main utility class for the AOC_MOD library |
Functions¶
|
utility function to get current year and day from the |
|
utility function to read in puzzle input and |
Module Contents¶
- aoc_mod.utilities.URL_PUZZLE_MAIN = 'https://adventofcode.com/{YEAR}/day/{DAY}'¶
- aoc_mod.utilities.URL_PUZZLE_INPUT = 'https://adventofcode.com/{YEAR}/day/{DAY}/input'¶
- aoc_mod.utilities.URL_PUZZLE_ANSWER = 'https://adventofcode.com/{YEAR}/day/{DAY}/answer'¶
- exception aoc_mod.utilities.AocModError(msg)¶
Bases:
ExceptionGeneral exception for an AOC_MOD library error
- class aoc_mod.utilities.AocMod(session_id: str = '')¶
Main utility class for the AOC_MOD library
- curr_time¶
- user_agent = 'https://github.com/cosmos1255/aoc_mod by cosmos1255'¶
- _cache_file¶
- _cache_data¶
- _time_to_wait_after_pull = 120¶
- _get_auth_data() str¶
will return the SESSION_ID environment variable, if set
- Returns:
the SESSION_ID env variable or empty string
- Return type:
str
- _get_current_time() time.struct_time¶
get current local time
- Returns:
current local time
- Return type:
time.struct_time
- _get_cache_data() dict¶
get the cache data from the cache file
- Returns:
the cache data as a dictionary
- Return type:
dict
- _set_cache_data(cache_data: dict) None¶
set the cache data in the cache file
- Parameters:
cache_data (dict) – the cache data to set
- _is_request_timed_out(last_pull_time: float) tuple[bool, int]¶
check if the last pull time is within the timeout period
- Parameters:
last_pull_time (float) – the time of the last pull in seconds since epoch
- Returns:
a tuple of (is_timed_out, timed_out_seconds_left) where is_timed_out is a boolean indicating if the request is timed out and timed_out_seconds_left is the number of seconds left until the timeout expires
- Return type:
tuple[bool, int]
- get_puzzle_instructions(year: int, day: int) str¶
get puzzle instructions for the entered (or current) year and day
- Parameters:
year (int) – year of AoC puzzle, defaults to current
day (int) – day of AoC puzzle, defaults to current
- Raises:
AocModError – exception if we http request throws an error
- Returns:
markdownify output string of puzzle instructions
- Return type:
str
- get_puzzle_input(year: int = 0, day: int = 0) str¶
get puzzle input for specified year and day
- Parameters:
year (int, optional) – yeah of the puzzle, defaults to 0
day (int, optional) – day of the puzzle, defaults to 0
- Raises:
AocModError – will raise for http request error or a request exception
- Returns:
the puzzle input as a string
- Return type:
str
- submit_answer(year: int, day: int, level: int, answer: int) str¶
submit puzzle answer for the year, day and level (part)
- Parameters:
year (int) – year of the puzzle
day (int) – day of the puzzle
level (int) – puzzle level or part (either 1 or 2)
answer (int) – the answer to be submitted
- Raises:
AocModError – will raise for http request error or a request exception
- Returns:
the result from the http post request
- Return type:
str
- aoc_mod.utilities.get_year_and_day(filepath: pathlib.Path) tuple[int, int]¶
utility function to get current year and day from the path to this file
- Parameters:
filepath (Path) – path to this file
- Returns:
a tuple with (year, day) as int values. will return (0, 0) on a failure
- Return type:
tuple[int, int]
- aoc_mod.utilities.parse_input(input_path: pathlib.Path) list[str]¶
utility function to read in puzzle input and place it into a list of str values
- Parameters:
input_path (Path) – path to the input file
- Returns:
a list of strings representing the input
- Return type:
list[str]