User Input/Output

Utility Functions

mil_tools.get_ch()[source]

Gets a single character from stdin. Doesn’t echo to screen. Catches CTRL-C and CTRL-E and raises exceptions.

Raises

FPrintFactory

Methods
class mil_tools.FprintFactory(title: Optional[str] = None, time: Optional[Callable] = None, msg_color: Optional[str] = None, auto_bold: bool = True, newline: int = 1)[source]

Factory method for producing a printer with the specified characteristics.

Parameters
  • title (Optional[str]) – The title to produce with each printed message.

  • time (Optional[Callable]) – A method for getting the time to produce with each method. If None, then no time is sent with a message.

  • msg_color (Optional[str]) – The color of each message. If None, defaults to white.

  • auto_bold (bool) – Automatically bolds each method. Defaults to True.

  • newline (int) – The number of newlines to print after each method.

fprint(text: str, **kwargs)[source]

Prints some text with the specified characteristics. Characteristics can be passed through the kwargs argument or through the class’ constructor.

Parameters
  • text (str) – The text to format and then print

  • kwargs – Any characteristics to print with the text. All keyword arguments are the same as the arguments specified in the constructor.

File Input/Output

Utility Functions

mil_tools.download(url: str, output_filename: Optional[str] = None) str[source]

Downloads the contents of a particular URL. If an output filename is also specified, the filename is written to with the URL contents.

Parameters
  • url (str) – The URL to obtain contents from.

  • output_filename (str) – The filename of the output file to write the contents.

Returns

The HTML contents of the URL.

Return type

str

mil_tools.download_and_unzip(url: str, output_dir: str)[source]

Downloads a zip file at a particular URL and unzips it to a directory.

Parameters
  • url (str) – The URL to obtain the zip file from.

  • output_dir (str) – The location of where to write the zip contents to.

Raises

IOError – The file at the URL could not be found/loaded.

Sanitization

Utility Functions

mil_tools.slugify(value: str) str[source]

Sanitizes any string into a string that is a valid filename or URL.

Normalizes string, converts to lowercase, removes non-alpha characters, and converts spaces to hyphens.

Parameters

value (str) – The value to sanitize.

Returns

The sanitized string.

Return type

str