PykeBot2.utils package

Submodules

PykeBot2.utils.config_master module

PykeBot2.utils.config_master.initialize_config_parser()
PykeBot2.utils.config_master.reload_config_file()
PykeBot2.utils.config_master.restore_defaults()

PykeBot2.utils.pb_logger module

Offers logging utilities for the entire program. Should be imported in every file as

“logger = logging.getLogger(“pb_logger”)”

author

Jonathan Decker

PykeBot2.utils.pb_logger.setup_logger(logger_name: str = 'pb_logger', console_level=20, log_file_level=10, logs_to_keep: int = 20, create_log_files: bool = True, path_to_logs: Optional[pathlib.Path] = None) None
Description

Sets up a logger with formatting, log file creation, settable console and log file logging levels as well as automatic deletion of old log files.

Parameters
  • logger_name (str) – Name of the logger profile, standard is pb_logger, this should not be changed except for testing

  • console_level (logging level) – logging level on console, standard is INFO

  • log_file_level (logging level) – logging level in log file, standard is DEBUG

  • logs_to_keep (int) – number of log files to keep before deleting the oldest one, standard is 20

  • create_log_files (bool) – Whether to create log files or only log to console

  • path_to_logs (pathlib.PATH) – path to the directory for saving the logs, standard is current working directory / logs

Returns

None, but the logger may now be accessed via logging.getLogger(logger_name), standard is pb_logger

Return type

None

PykeBot2.utils.token_loader module

Offers utility for loading API Tokens from a file or environmental variable.

author

Jonathan Decker

PykeBot2.utils.token_loader.load_token(name: str, try_env: bool = True, hide_token: bool = True, path_to_token: Optional[pathlib.Path] = None) str
Description

Loads the specified token, trying either the given path or the cwd and if set the env variables

Parameters
  • name (str) – Name of the token, as in the file_name or the name of the env variable

  • try_env (bool) – Sets whether environmental variables should be checked if the token is not in the given path, standard is True

  • hide_token (bool) – Sets whether the token should be hidden from logging, standard is True

  • path_to_token (pathlib.Path) – Path to the folder containing the token, should not include the token itself, standard is the cwd

Returns

The token as in the first line of the token file or the value of the env variable of the same name

Return type

str

Raises

TokenLoadingError

Module contents