hal.streams package

Submodules

hal.streams.logger module

Logging module

hal.streams.logger.get_custom_logger(logger_name)[source]
hal.streams.logger.get_logger()[source]

Gets default logger

Returns:logger
hal.streams.logger.log_error(*error, cause=None)[source]

Logs error

Parameters:
  • error – error to log
  • cause – (optional) cause of error
hal.streams.logger.log_message(*message)[source]

Logs message

Parameters:message – message to log

hal.streams.markdown module

Markdown r/w models

class hal.streams.markdown.MarkdownItem(text, item_type, attributes=None)[source]

Bases: object

Models anything that can be written in Markdown

ATTRIBUTES = ['ref', 'size']
TYPES = ['text', 'url', 'image', 'title']
to_markdown()[source]

Converts to markdown :return: item in markdown format

class hal.streams.markdown.MarkdownTable(labels, table)[source]

Bases: object

Models and writes a table to .md

to_markdown()[source]

Converts to markdown :return: item in markdown format

hal.streams.pretty_table module

Pretty prints table in SQL style

class hal.streams.pretty_table.SqlTable(labels, data, num_format, line_separator)[source]

Bases: object

Table in SQL-syntax like form

build()[source]

Builds pretty-formatted table

Returns:pretty table
static from_df(data_frame)[source]

Parses data and builds an instance of this class

Parameters:data_frame – pandas DataFrame
Returns:SqlTable
get_blank_row(filler='-', splitter='+')[source]

Gets blank row

Parameters:
  • filler – Fill empty columns with this char
  • splitter – Separate columns with this char
Returns:

Pretty formatted blank row (with no meaningful data in it)

get_pretty_row(row, filler, splitter)[source]

Gets pretty-formatted row

Parameters:
  • row – List of data
  • filler – Fill empty columns with this char
  • splitter – Separate columns with this char
Returns:

Pretty formatted row

pretty_format_row(row, filler=' ', splitter='|')[source]

Gets pretty-formatted row

Parameters:
  • row – List of data
  • filler – Fill empty columns with this char
  • splitter – Separate columns with this char
Returns:

Pretty formatted row

hal.streams.pretty_table.parse_colorama(text)[source]

Parses colorama

Parameters:text – Colorama text to parse
Returns:Parsed colorama text
hal.streams.pretty_table.pretty_df(data_frame)[source]

Parses data and builds an instance of this class

Parameters:data_frame – pandas DataFrame
Returns:Pretty formatted table (first row is labels, then actual data)
hal.streams.pretty_table.pretty_dicts(dicts)[source]

Converts list of dicts to data frame, then calls ‘pretty_df’

Parameters:dicts – list of dicts
Returns:Pretty formatted table (first row is labels, then actual data)
hal.streams.pretty_table.pretty_format_table(labels, data, num_format='{:.3f}', line_separator='\n')[source]

Parses and creates pretty table

Parameters:
  • labels – List of labels of data
  • data – Matrix of any type
  • num_format – Format numbers with this format
  • line_separator – Separate each new line with this
Returns:

Pretty formatted table (first row is labels, then actual data)

hal.streams.user module

Deal with user on standard output/input

class hal.streams.user.UserInput(yes_choices=None, no_choices=None, threshold=None, interactive=True)[source]

Bases: object

Chat with user and ask questions

NO_INPUT = ['no', 'not ok', 'none']
THRESHOLD_INPUT = 0.9
YES_INPUT = ['yes', 'ok', 'fine']
get_answer(question)[source]

Asks user a question, then gets user answer

Parameters:question – Question: to ask user
Returns:User answer
get_list(question, splitter=', ', at_least=0, at_most=inf)[source]

Parses answer and gets list

Parameters:
  • question – Question: to ask user
  • splitter – Split list elements with this char
  • at_least – List must have at least this amount of elements
  • at_most – List must have at most this amount of elements
Returns:

User answer

get_number(question, min_i=-inf, max_i=inf, just_these=None)[source]

Parses answer and gets number

Parameters:
  • question – Question: to ask user
  • min_i – min acceptable number
  • max_i – max acceptable number
  • just_these – Accept only these numbers
Returns:

User answer

get_yes_no(question)[source]

Checks if question is yes (True) or no (False)

Parameters:question – Question to ask user
Returns:User answer
is_no(answer)[source]

Checks if considered a “yes” answer

Parameters:answer – User answer
Returns:True iff considered a “yes” answer
is_yes(answer)[source]
Parameters:answer – User: answer
Returns:True iff considered a “yes” answer
re_ask(with_help=True)[source]

Re-asks user the last question

Parameters:with_help – True iff you want to show help on how to answer questions
Returns:user answer
show_help()[source]

Prints to stdout help on how to answer properly