adgtk.utils.formatting

Used for dealing with formatting and parsing of strings.

exception adgtk.utils.formatting.UnableToProcess(message: str = 'Unable to process.')

Bases: Exception

Used for failing to process and wanting to degrade gracefully

__init__(message: str = 'Unable to process.')
default_msg = 'Unable to process.'
adgtk.utils.formatting.clean_and_process_possible_yaml(text: str) list

cleans up via some simple pre-determined rules and attempts to locate and process yaml entries in text. This is useful for when there are multiple entries interlaced with text such as when a LLM adds text such as “and here is another…”, etc. Best practice is to run process_possible_yaml and let it invokes this function.

Parameters:

text (str) – the text to process as potential yaml

Returns:

a list of dict that contains the results of processing.

Return type:

list

adgtk.utils.formatting.count_prefix_spaces(text: str) int
adgtk.utils.formatting.get_timestamp_now(include_time: bool = True) str

Generates a string with a timestamp. The goal is to have a consistent data and date/time format across the different reports, etc.

Args:
include_time (bool, optional): Include time?.

Defaults to True.

Returns:

str: A timestamp string formatted for reports, etc.

adgtk.utils.formatting.process_possible_yaml(text: str) list

Provides a first attempt at processing YAML. This is ideal when the text is properly formatted and a single entry. If direct processing fails then this function invokes an attempt to cleanup and process that text. This should be invoked as a first attempt for text that is likely yaml or at least processable via yaml.

Parameters:

text (str) – the text to process as potential yaml

Returns:

a list of dict that contains the results of processing.

Return type:

list