def live(ctx: click.Context, **args: str) -> None: """ Show live departures and arrivals for a train station. \b Examples: locomotive live "Paris Montparnasse" """ stations = ctx.obj["stations"] station = stations.find_or_raise(args["station"]) client = Client(stations) dep_gs = None arr_gs = None if args["color"]: dep_gs = tf.AlternatingRowGrid(bg(25), bg(18)) arr_gs = tf.AlternatingRowGrid(bg(34), bg(28)) departures = client.board_request(BoardRequest(station, "departure")) cols = ["Destination", "Number", "Time", "Delay", "Platform"] click.echo(tf.generate_table(get_rows(departures), cols, grid_style=dep_gs)) arrivals = client.board_request(BoardRequest(station, "arrival")) cols = ["Origin", "Number", "Time", "Delay", "Platform"] click.echo(tf.generate_table(get_rows(arrivals), cols, grid_style=arr_gs))
def ptable(self, rows, columns, grid_args, row_stylist): """Format tabular data for pretty-printing as a fixed-width table and then display it using a pager. :param rows: required argument - can be a list-of-lists (or another iterable of iterables), a two-dimensional NumPy array, or an Iterable of non-iterable objects :param columns: column headers and formatting options per column :param grid_args: argparse arguments for formatting the grid :param row_stylist: function to determine how each row gets styled """ if grid_args.color: grid = tf.AlternatingRowGrid(BACK_PRI, BACK_ALT) elif grid_args.fancy: grid = tf.FancyGrid() elif grid_args.sparse: grid = tf.SparseGrid() else: grid = None transpose = False if grid_args.transpose: transpose = True formatted_table = tf.generate_table(rows=rows, columns=columns, grid_style=grid, row_tagger=row_stylist, transpose=transpose) self.ppaged(formatted_table, chop=True)
def get_scratched_ticket(self): new_tkt = self.ticket self.ticket = [ strike_through(x) if x in list(set(self.ticket) - set(self.remaining_ticket)) else "\033[1;31m" + str(x) + "\033[1;31m" for x in new_tkt ] np_ticket = np.array(self.ticket) shape = constants.NUMPY_SHAPE[len(self.ticket)] np_ticket = np_ticket.reshape(shape[0], shape[1]) print( tf.generate_table(np_ticket, grid_style=tf.AlternatingRowGrid( BACK_GREEN, BACK_BLUE)))
def __str__(self) -> str: order_keys = ['value', 'hesse'] keys = OrderedSet() for pdict in self.values(): keys.update(OrderedSet(pdict)) order_keys = OrderedSet([key for key in order_keys if key in keys]) order_keys.update(keys) rows = [] for param, pdict in self.items(): row = [param.name] row.extend(format_value(pdict.get(key, ' ')) for key in order_keys) row.append( color_on_bool(run(param.at_limit), on_true=colored.bg('light_red'), on_false=False)) rows.append(row) order_keys = ['name'] + list(order_keys) + ['at limit'] return tafo.generate_table(rows, order_keys, grid_style=tafo.AlternatingRowGrid( colored.bg(15), colored.bg(254)))
# coding=utf-8 """ Unit testing of tableformatter with simple cases - with a list of tuples as table entries - using a list of objects for the table entries """ import pytest import tableformatter as tf from collections import namedtuple # Make the test results reproducible regardless of what color libraries are installed tf.TableColors.set_color_library('none') tf.set_default_grid(tf.AlternatingRowGrid('', '', '')) class MyRowObject(object): """Simple object to demonstrate using a list of objects with TableFormatter""" def __init__(self, field1: str, field2: str, field3: int, field4: int): self.field1 = field1 self.field2 = field2 self._field3 = field3 self.field4 = field4 def get_field3(self): """Demonstrates accessing object functions""" return self._field3 NamedTupleRow = namedtuple('NamedTupleRow', 'field1,field2,field3,field4') """Example named tuple to demonstrate usage with TableFormatter"""
imp.find_module('befe_config') import befe_config as befe_config except ImportError: print(Colors.RED + "befe_config.py not found" + Colors.ENDC) print( Colors.RED + "Please make a copy of the befe_config_example.py and name it befe_config.py, and edit it as needed to reflect the configuration of your setup" + Colors.ENDC) print( Colors.RED + "In most cases the example config without modifications will work as a starting point" + Colors.ENDC) exit(1) FULL_TABLE_GRID_STYLE = tf.FancyGrid() DEFAULT_TABLE_GRID_STYLE = tf.AlternatingRowGrid() def get_befe_scripts_dir(): scripts_dir = os.environ.get('BEFE_SCRIPT_DIR') return scripts_dir def get_config(config_name): return eval("befe_config." + config_name) def config_exists(config_name): return hasattr(befe_config, config_name)
""" import tableformatter as tf from tableformatter import generate_table try: from colorama import Back BACK_RESET = Back.RESET BACK_GREEN = Back.LIGHTGREEN_EX BACK_BLUE = Back.LIGHTBLUE_EX except ImportError: try: from colored import bg BACK_RESET = bg(0) BACK_BLUE = bg(27) BACK_GREEN = bg(119) except ImportError: BACK_RESET = '' BACK_BLUE = '' BACK_GREEN = '' rows = [('A1', 'A2', 'A3', 'A4'), ('B1', 'B2\nB2\nB2', 'B3', 'B4'), ('C1', 'C2', 'C3', 'C4'), ('D1', 'D2', 'D3', 'D4')] columns = ('Col1', 'Col2', 'Col3', 'Col4') print("Table with colorful alternating rows") print( generate_table(rows, columns, grid_style=tf.AlternatingRowGrid(BACK_GREEN, BACK_BLUE)))