def play_baccarat(): balance = BaccaratBalance() cls() table_data = [[' PLAYER ', ' BANKER '], ['Player pays', '1:1'], ['Tie pays', '8:1'], ['Banker pays', '0.95:1'], ['Total balance', str(balance.total)]] table_instance = SingleTable(table_data, '[ BACCARAT ]') table_instance.justify_columns = {0: 'right', 1: 'left'} print(table_instance.table) # prepare deck and balance deck = BaccaratDeck() deck.build() deck.shuffle() balance = BaccaratBalance() input("Press any key to start") is_playing = True while is_playing: # prepare hands player = Hand() banker = Hand() place_bets(balance) deal_initial_cards(deck, player, banker) p3_card = process_3rd_card_player(deck, player) b3_card = process_3rd_card_banker(deck, banker, p3_card) table_data = [ [ ' PLAYER [' + str(player.score) + ']', '[' + str(banker.score) + '] BANKER ' ], [ str(p3_card) + str(player.cards[0]) + str(player.cards[1]), str(banker.cards[0]) + str(banker.cards[1]) + str(b3_card) ] ] table_instance = SingleTable(table_data, '[ BACCARAT ]') table_instance.justify_columns = {0: 'right', 1: 'left'} cls() print(table_instance.table) game_result(player, banker, balance) next_round = input( "\nWould you like to play again? \nPress any key to continue or 'q' to quit:" ).lower() if next_round != 'q': continue else: is_playing = False
def list_all(): print '\n{}ENCODERS{}'.format(logs.bold(logs.purple('>>')),logs.bold(logs.purple('<<'))) table_data = [['--NAME--', '--ARCH--', '--DESCRIPTION--', '--RANK--']] encoders = [] for enc in os.walk(PATH+'encoders'): encoders.append(enc) encoders = encoders[0][2] cdrs = [] for enc in encoders: if ('init' in enc or '.pyc' in enc): pass else: cdrs.append(enc.replace('.py', '')) for encoder in cdrs: try: encoder = importlib.import_module('encoders.'+encoder).Encoder() if encoder.rank == 'unstable': rank = logs.red('UNSTABLE') if encoder.rank == 'manual': rank = logs.yellow('MANUAL') elif encoder.rank == 'good': rank = logs.green('GOOD') elif encoder.rank == 'excellent': rank = logs.blue('EXCELLENT') except: rank = 'N/A' table_data.append([encoder.name, encoder.arch, encoder.description, rank]) table_instance = SingleTable(table_data) table_instance.inner_heading_row_border = True table_instance.inner_row_border = False table_instance.justify_columns = {0: 'left', 1: 'left', 2: 'left'} print table_instance.table print '\n{}EGGHUNTERS{}'.format(logs.bold(logs.purple('>>')),logs.bold(logs.purple('<<'))) table_data = [['--NAME--', '--PLATFORM--', '--SIZE--', '--EGG SIZE--']] for egg in eggs: table_data.append([egg, eggs[egg][1],'{} bytes'.format(eggs[egg][2]),'{} bytes'.format(eggs[egg][3])]) table_instance = SingleTable(table_data) table_instance.inner_heading_row_border = True table_instance.inner_row_border = False table_instance.justify_columns = {0: 'left', 1: 'left', 2: 'left'} print table_instance.table print '\n{}FORMATS{}'.format(logs.bold(logs.purple('>>')),logs.bold(logs.purple('<<'))) table_data = [['--FORMAT--', '--DESCRIPTION--']] for func in dir(wrappers): if "format_" in func: table_data.append([func.replace("format_", ''), eval("wrappers.{}".format(func)).__doc__]) table_instance = SingleTable(table_data) table_instance.inner_heading_row_border = True table_instance.inner_row_border = False table_instance.justify_columns = {0: 'left', 1: 'left', 2: 'left'} print table_instance.table
def printInformation(session): """ Prints out Information about all created virtual machines """ print "\n\n=================[ VIRTUAL MACHINES ]=================\n" table_data = [['VM', 'CLUSTER','TEMPLATE', 'STORAGE DOMAIN', 'MEMORY', 'DISKS', 'INTERFACES']] for vm in configFile['vms']: hostname = vm['hostname'] cluster = vm['cluster'] template = vm['template'] storageDomain = vm['storage-domain'] memory = vm['memory'] diskInfo = "" nicInfo = "" for disk in vm['disks']: diskSize = vm['disks'][disk] diskInfo += disk +" (" + str(diskSize) + " GB)\n" for nic in vm['interfaces']: network = vm['interfaces'][nic] nicInfo += network + " (" + nic + ")\n" table_data += [[ hostname, cluster, template, storageDomain, str(memory) + " GB", diskInfo, nicInfo ]] table = SingleTable(table_data) table.inner_row_border = True table.justify_columns = {0: 'center' , 1: 'center', 2: 'center',3 : 'center', 4: 'center', 5: 'center', 6 : 'center'} print table.table
def viewSentiments(number): twits = getFile() table_data = [[ Color('{cyan}TWEET{/cyan}'), Color('{autored}SENTIMENTS{/autored}') ]] for twit in tqdm(twits.items(), total=number, desc="Analysing sentiments..."): sentiment = twit[1]['sentiments'] sentString = '' for item in sentiment: sentString += item + '\n' sentString = sentString.strip() text = '\n'.join(wrap(twit[1]['tweet'], 80)) table_data.append([ Color('{cyan}' + text + '{/cyan}'), Color('{red}' + sentString + '{/red}') ]) table_instance = SingleTable(table_data, Color('{green}Sentiment Analysis{/green}')) table_instance.inner_heading_row_border = True table_instance.inner_row_border = True table_instance.justify_columns = {0: 'left', 1: 'left'} return table_instance.table
def viewRanks(number): twits = getFile() stopWords = getStopwords() words = [] for twit in tqdm(twits.items(), total=number, desc="Ranking words..."): words.extend(word_tokenize(twit[1]['tweet'])) words = [ word for word in words if word.lower() not in stopWords and re.match(r'\w', word) ] wordsDict = Counter(words) sortedList = sorted(wordsDict.items(), key=lambda x: x[1], reverse=True) table_data = [[ Color('{cyan}WORDS{/cyan}'), Color('{autored}RANKS{/autored}') ]] for word in sortedList: table_data.append( [Color(word[0]), Color('{autored}' + str(word[1]) + '{/autored}')]) table_instance = SingleTable(table_data, Color('{green}Word Frequency{/green}')) table_instance.inner_heading_row_border = True table_instance.inner_row_border = True table_instance.justify_columns = {0: 'center', 1: 'center'} return table_instance.table
def display_board(self): self.clear_screen() current_round = self.rounds[self.current_round] board_data = [sorted(list(current_round.keys()))] values = set() for category in current_round: for val in current_round[category]: values.add(val) for val in sorted(values): row = [] for key in sorted(current_round.keys()): if current_round[key].get(val, {}).get('active', False): row.append('\n' + colored(f'${val:,}', 'yellow') + '\n') else: row.append('\n\n') board_data.append(row) board = SingleTable(board_data, f'Round {self.current_round}') board.inner_row_border = True board.justify_columns = {k: 'center' for k, idx in enumerate(current_round.keys())} self.render_scores() print('\n') for line in str(board.table).splitlines(): self.print_centered(line, width=board.table_width) self.load_clue(self.prompt_centered('Pick a clue'))
def main(): user_inp = str(raw_input('Enter the ip address : ')).strip() ip = IPAddress(str(user_inp)) if ip.version == 4: ipaddr = user_inp elif ip.version == 6: ipaddr = user_inp.replace(":","%3A") else: print "Please enter only a valid ipv4 or ipv6 address" sys.exit() tor_result = torproject(ipaddr) status,asn,owner,isp,continent,country,city,region = blacklist(ipaddr) table_data = [["ASN",asn], ["Owner",owner], ["ISP",isp], ["TorNode",tor_result], ["Blacklist",status], ["City",city], ["Region",region], ["Continent",continent], ["Country",country]] table = SingleTable(table_data) table.title = ipaddr table.justify_columns = {0: 'center', 1: 'center'} table.inner_row_border = True print "" print table.table
def estadosEnCaja(self, nombrecaja): '''Muestra la cantidad de estados diferentes en una caja''' pipeline = [{ '$match': { 'caja': nombrecaja } }, { '$group': { '_id': '$estado', 'cantidad': { '$sum': 1 } } }] estados = list(db.aggregate(pipeline)) #Crea tabla table_data = [[ Color('{autocyan}Estado{/cyan}'), Color('{autocyan}Cantidad{/cyan}') ]] total = 0 for estado in estados: table_data.append([estado['_id'], estado['cantidad']]) total += estado['cantidad'] table_data.append([ Color('{autocyan}Total:{/cyan}'), Color('{autocyan}' + str(total) + '{/cyan}') ]) table = SingleTable(table_data) table.title = nombrecaja table.justify_columns = {0: 'right'} print(table.table)
def main(): db = dbhandler.connect_db_judged( "127.0.0.1", "root", "sustcse", "uva_crawler") os.system("clear") print bcolors.BOLD + bcolors.HEADER + " Problem Recomendation system for SourceCode" + bcolors.ENDC + "\n" while True: p = raw_input("Type user_id or exit : ") # os.system("clear") print "\n" if p == "exit": break obj = Recommend(db, int(p)) data = [[bcolors.WARNING+"pid"+bcolors.ENDC,bcolors.WARNING+"Title"+bcolors.ENDC]] for p in obj.rec_prob: query = "SELECT name FROM problems WHERE pid=" + str(p["pid"]) pname = dbhandler.parse_db(db, query) temp = [p["pid"],pname[0][0]] data.append(temp) table = SingleTable(data) table.inner_row_border = True table.justify_columns={1:"center"} print bcolors.CYAN + "Recommended problems : " + bcolors.ENDC print table.table print "\n" dbhandler.disconnect_db_judge(db)
def transfer_pokemon(self): pokemon_list = [p for p in self.pokemon if p.get('transfer', False) and not p['is_favorite'] and not p['is_shiny'] and not p['has_costume']] total_transfers = len(pokemon_list) transfers_completed = 0 if not pokemon_list: print u'No Pokémon scheduled to transfer.' return table_data = [ [u'Pokémon', 'CP', 'IV %', 'ATK', 'DEF', 'STA'] ] print 'About to transfer %d Pokémon…' % total_transfers transfer_list = [] for pokemon in pokemon_list: # Remove the Pokémon from the list, so that we don’t try to rename # it later. self.pokemon.remove(pokemon) pokedex_number = pokemon['pokedex_number'] pokemon_name = self.pokemon_list[str(pokedex_number)] table_data.append([ pokemon_name, pokemon['cp'], '{0:.0f}%'.format(pokemon['iv_percent']), pokemon['attack'], pokemon['defense'], pokemon['stamina'] ]) transfer_list.append(pokemon['id']) table = SingleTable(table_data) table.justify_columns = { 0: 'left', 1: 'right', 2: 'right', 3: 'right', 4: 'right', 5: 'right', 6: 'left' } print u'The following Pokémon are about to be transferred:' print table.table # After logging in, wait a while before starting to rename Pokémon, like a # human player would. self.config.min_delay = total_transfers * 2 self.config.max_delay = total_transfers * 4 self.wait_randomly() response = self.api.release_pokemon(pokemon_ids=transfer_list) try: result = response['responses']['RELEASE_POKEMON']['result'] except KeyError: print 'Failed:' print response status = 'error' pass else: if result == 1: status = 'success' print 'Transfer successful.' else: status = 'error' print 'Transfer failed. Error code: %s' % str(result)
def print_table(table_headers, table_values, table_title='', table_view='v'): os.system("cls") if table_view == 'v': table_data = [table_headers] for i in range(len(table_values[0])): dataline = [] for j in range(len(table_headers)): dataline.append(str(table_values[j][i])) table_data.append(dataline) elif table_view == 'h': table_data = [] for i in range(len(table_values)): table_data.append([table_headers[i]] + list(map(str, table_values[i]))) table = SingleTable(table_data) table.title = table_title table.justify_columns = {0: 'left', 1: 'left', 2: 'left'} table.inner_row_border = False print(table.table)
def createWD(self): # Create WeatherDescription, 天氣預報綜合描述 # Prepare Table Payload payload = [ ["時間(接下來三小時內預測)", "敘述"] ] for wdData in self.rawData["WeatherDescription"]["time"]: payload.append([ wdData["startTime"], wdData["elementValue"][0]["value"] ]) # Create Table table = SingleTable(payload, "天氣預報綜合描述") # Custom Table table.padding_left = 2 table.padding_right = 2 table.justify_columns = { 0: "center", 1: "left" } # Return Table String return table.table
def createWx(self): # Create Wx, 天氣現象 # Prepare Table Payload payload = [ ["時間(接下來三小時內預測)", "形容"] ] for data in self.rawData["Wx"]["time"]: payload.append([ data['startTime'], data["elementValue"][0]["value"] ]) # Create Table table = SingleTable(payload, self.rawData['Wx']['description']) # Custom Table table.padding_left = 2 table.padding_right = 2 table.justify_columns = { 0: "center", 1: "center" } # Return Table String return table.table
def do_w(self, arg): 'Show watchlist w \nAdd to watchlist w a <symbol> \nRemove from watchlist w r <symbol>' parts = arg.split() if len(parts) == 2: if parts[0] == 'a': self.watchlist.append(parts[1].strip()) if parts[0] == 'r': self.watchlist = [r for r in self.watchlist if not r == parts[1].strip()] print "Done" else: watch_t_data=[] watch_table = SingleTable(watch_t_data,'Watch List') watch_table.inner_row_border = True watch_table.justify_columns = {0: 'center', 1: 'center', 2: 'center', 3:'center',4: 'center'} watch_t_data.append(["Symbol","Ask Price", "Open", "Today", "%"]) if len(self.watchlist) > 0: raw_data = self.trader.quotes_data(self.watchlist) quotes_data = {} for quote in raw_data: day_change = float(quote['last_trade_price']) - float(quote['previous_close']) day_change_pct = '{:05.2f}'.format(( day_change / float(quote['previous_close']) ) * 100) watch_t_data.append([ quote['symbol'], '{:05.2f}'.format(float(quote['last_trade_price'])), '{:05.2f}'.format(float(quote['previous_close'])), color_data(day_change), color_data(day_change_pct) ]) print(watch_table.table) else: print "Watchlist empty!"
def get_grid(self, astype='table'): from pandas import DataFrame as df geoms = self.geometries().keys() phases = [p.name for p in self.phases().values() if not hasattr(p, 'mixture')] grid = df(index=geoms, columns=phases) for r in grid.index: for c in grid.columns: phys = self.find_physics(phase=self[c], geometry=self[r]) if phys is not None: grid.loc[r][c] = phys.name else: grid.loc[r][c] = '---' if astype == 'pandas': pass elif astype == 'dict': grid = grid.to_dict() elif astype == 'table': from terminaltables import SingleTable headings = [self.network.name] + list(grid.keys()) g = [headings] for row in list(grid.index): g.append([row] + list(grid.loc[row])) grid = SingleTable(g) grid.title = 'Project: ' + self.name grid.padding_left = 3 grid.padding_right = 3 grid.justify_columns = {col: 'center' for col in range(len(headings))} elif astype == 'grid': grid = ProjectGrid() return grid
def do_o(self, arg): 'List open orders' open_orders = self.trader.get_open_orders() if open_orders: open_t_data=[] open_table = SingleTable(open_t_data,'open List') open_table.inner_row_border = True open_table.justify_columns = {0: 'center', 1: 'center', 2: 'center', 3:'center',4: 'center'} open_t_data.append( ["index", "symbol", "price", "quantity", "type", "id"]) index = 1 for order in open_orders: if order['trigger'] == 'stop': order_price = order['stop_price'] order_type = "stop loss" else: order_price = order['price'] order_type = order['side']+" "+order['type'] open_t_data.append([ index, self.get_symbol(order['instrument']), order_price, int(float(order['quantity'])), order_type, order['id'], ]) index += 1 print((open_table.table)) else: print("No Open Orders")
def do_q(self, arg): 'Get detailed quote for stock: q <symbol(s)>' symbols = re.split('\W+',arg.upper()) if len(arg) == 0: print("Missing symbol(s)") else: instruments = [self.get_instrument(s)['url'] for s in symbols] raw_data = self.trader.get_stock_marketdata(instruments) quotes_data = {} quote_t_data=[] quote_table = SingleTable(quote_t_data,'Quote List') quote_table.inner_row_border = True quote_table.justify_columns = {0: 'center', 1: 'center', 2: 'center', 3:'center',4: 'center'} quote_t_data.append(["Symbol", "Current Price", "Open","Change", "Ask","Bid"]) for quote in raw_data: if not quote: continue day_change = float(quote['last_trade_price']) - float(quote['previous_close']) day_change_pct = ( day_change / float(quote['previous_close']) ) * 100 ask_price = '{:05.2f}'.format(float(quote['ask_price'])) ask_size = quote['ask_size'] bid_price = '{:05.2f}'.format(float(quote['bid_price'])) bid_size = quote['bid_size'] quote_t_data.append([ quote['symbol'], '{:05.2f}'.format(float(quote['last_trade_price'])), '{:05.2f}'.format(float(quote['previous_close'])), color_data(day_change)+' ('+color_data('{:05.2f}'.format(day_change_pct))+'%)', str(ask_price)+' x '+str(ask_size), str(bid_price)+' x '+str(bid_size) ]) print((quote_table.table))
def cars_with_no_drivers(self): cars_ = self.statisticsService.cars_with_no_drivers() if cars_ != {}: table_contents = [["Car brand", "Car registration"]] for car_brand in cars_: table_contents.append([car_brand, cars_[car_brand]]) table = SingleTable(table_contents, title="Cars with no driver associated") table.justify_columns = { 0: "center", 1: "center", } while True: console.clear_console() print(table.table) input_ = input("Type b or back to go back > ") if input_ == "b" or input_ == "back": break else: continue else: olt.show(title="Cars with no driver associated", message="All cars have at least a driver associated")
def createATandT(self): # Create T, AT 溫度, 體感溫度 # Prepare Table Payload payload = [ ["時間(接下來三小時內預測)", "溫度(C)", "體感溫度(C)"] ] for tData, atData in zip(self.rawData["T"]["time"], self.rawData["AT"]["time"]): payload.append([ tData["dataTime"], tData["elementValue"][0]["value"], atData["elementValue"][0]["value"] ]) # Create Table table = SingleTable(payload, "溫度與體感溫度") # Custom Table table.padding_left = 2 table.padding_right = 2 table.justify_columns = { 0: "center", 1: "center", 2: "center" } # Return Table String return table.table
def createPopandRH(self): # Create PoP6h, RH 6小時降雨機率, 相對濕度 # Prepare Table Payload payload = [ ["時間(接下來六小時內預測)", "相對濕度(%)", "降雨機率(%)"] ] for popData, rhData in zip(self.rawData["PoP6h"]["time"], [d for idx, d in enumerate(self.rawData["RH"]["time"]) if idx % 2 == 0]): payload.append([ popData["startTime"], rhData["elementValue"][0]["value"], popData["elementValue"][0]["value"] ]) # Create Table table = SingleTable(payload, "相對濕度與降雨機率") # Custom Table table.padding_left = 2 table.padding_right = 2 table.justify_columns = { 0: "center", 1: "center", 2: "center" } # Return Table String return table.table
def handle_remove_driver(driver_repo: Repo, parser: Parser): """ Handle removing a driver Args: driver_repo (Repo): Driver repository parser (Parser): Input parser """ # Get driver id: done_id = False _, driver_list = driver_repo.get() while not done_id: id_ = input( "Enter driver id (numeric) or leave blank to see the driver list > " ) if id_ == "": table_data = [["ID", "Name"]] for driver in driver_list: table_data.append([str(driver.id), driver.name]) driver_table = SingleTable(table_data, title="Drivers") driver_table.justify_columns = { 0: "left", 1: "center", } while True: console.clear_console() print(driver_table.table) input_ = input("Type b or back to go back > ") if input_ == "b" or input_ == "back": break else: continue else: try: id_ = int(id_) if parser.check_if_already_exists(by_id=True, id=id_): # Id exists, continue: done_id = True driver_repo.delete(entity_id=id_) save_data(mode="single", only="drivers", driver_instance_list=driver_list) olt.show(title="Success", message="The driver was removed succesfully") except ValueError: console.clear_console() olt.show(title="Info", message="Invalid ID! The ID Must be numeric", go_back=False) else: console.clear_console() olt.show(title="Info", message="Invalid ID!", go_back=False)
def draw_updated_grid(): table_instance = SingleTable(table_data, 'Play Game') table_instance.inner_heading_row_border = False table_instance.inner_row_border = True table_instance.justify_columns = { 0: 'center', 1: 'center', 2: 'center', 3: 'center' } print(table_instance.table)
def __report_summary_labels(self, cumulative): data = [("label", "status", "succ", "avg_rt", "error")] justify = {0: "left", 1: "center", 2: "right", 3: "right", 4: "left"} sorted_labels = sorted(cumulative.keys()) for sample_label in sorted_labels: if sample_label != "": data.append(self.__get_sample_element(cumulative[sample_label], sample_label)) table = SingleTable(data) if sys.stdout.isatty() else AsciiTable(data) table.justify_columns = justify self.log.info("Request label stats:\n%s", table.table)
def do_lo(self, arg): 'Lists current options portfolio' # Load Options options_t_data=[] option_positions = self.trader.options_owned() options_table = SingleTable(options_t_data,'Options') options_table.inner_row_border = True options_table.justify_columns = {0: 'center' } options_t_data.append(["Symbol","Type","Experation","Strike", "Price", "QTY", "Equity", "Cost", "Total Return","Today"]) for op in option_positions: quantity = float(op['quantity']) if quantity == 0: continue cost = float(op['average_price']) if op['type'] == 'short': quantity = -quantity cost = -cost instrument = op['option'] option_data = self.trader.session.get(instrument).json() # skip expired -- verify when it changes state day of or, after market close on expieration if option_data['state'] == "expired": continue expiration_date = option_data['expiration_date'] strike = float(option_data['strike_price']) type = option_data['type'] symbol = op['chain_symbol'] option_type = str(type).upper() expiration = expiration_date strike_price = '$'+str(strike) info = self.trader.get_option_marketdata(instrument) last_price = float(info['adjusted_mark_price']) total_equity = (100 * last_price) * quantity change = total_equity - (float(cost) * quantity) change_pct = '{:04.2f}'.format(change / float(cost) * 100) day_change = float(info['adjusted_mark_price']) - float(info['previous_close_price']) day_pct = '{:04.2f}'.format((day_change / float(info['previous_close_price']) ) * 100) # format after calc day_change = f"{day_change:.3f}" options_t_data.append([ symbol,option_type, expiration, strike_price , last_price, quantity, total_equity, cost, color_data(change) +' ('+ color_data(change_pct) +'%)', color_data(day_change) +' ('+ color_data(day_pct) +'%)' ]) print((options_table.table))
def table_server_status(): """Return table string to be printed.""" table_data = [ [Color('Low Space'), Color('{autocyan}Nominal Space{/autocyan}'), Color('Excessive Space')], [Color('Low Load'), Color('Nominal Load'), Color('{autored}High Load{/autored}')], [Color('{autocyan}Low Free RAM{/autocyan}'), Color('Nominal Free RAM'), Color('High Free RAM')], ] table_instance = SingleTable(table_data, '192.168.0.105') table_instance.inner_heading_row_border = False table_instance.inner_row_border = True table_instance.justify_columns = {0: 'center', 1: 'center', 2: 'center'} return table_instance.table
def main(): res = arguments() json_content = json.load(open(res.FILE)) table_data = [["SOURCE", "TYPE", "DATA"]] for result in json_content: table_data.append([red(result["source"]), blue(result["type"]), result["data"]]) table_instance = SingleTable(table_data) table_instance.inner_heading_row_border = True table_instance.inner_row_border = False table_instance.justify_columns = {0: 'left', 1: 'left', 2: 'left'} print(f"\n[*] Entries found: {len(json_content)}") print(table_instance.table) print("")
def do_qq(self, arg): 'Get quote for stock q <symbol> or option q <symbol> <call/put> <strike> <(optional) YYYY-mm-dd>' arg = arg.strip().split() try: symbol = arg[0].upper() except: print("Please check arguments again. Format: ") print("Stock: q <symbol>") print( "Option: q <symbol> <call/put> <strike> <(optional) YYYY-mm-dd>" ) type = strike = expiry = None if len(arg) > 1: try: type = arg[1] strike = arg[2] except Exception as e: print("Please check arguments again. Format: ") print("q <symbol> <call/put> <strike> <(optional) YYYY-mm-dd>") try: expiry = arg[3] except: expiry = None arg_dict = { 'symbol': symbol, 'type': type, 'expiration_dates': expiry, 'strike_price': strike, 'state': 'active', 'tradability': 'tradable' } quotes = self.trader.get_option_quote(arg_dict) qquote_t_data = [] qquote_table = SingleTable(qquote_t_data, 'Quote List') qquote_table.inner_row_border = True qquote_table.justify_columns = {0: 'center', 1: 'center'} qquote_t_data.append(['expiry', 'price']) for row in quotes: qquote_t_data.append(row) print((qquote_table.table)) else: try: self.trader.print_quote(symbol) except: print("Error getting quote for:", symbol)
def print_paragraph_stats(self): """This method, along with print_article_stats(), can be called to present paragraph stats on a command line. Ideally first call print_article_stats() and then this method. It shows sentence, average words per sentence, longest sentence, and readability scores (Flesch reading ease and Dale Chall readability scores) of paragraphs. """ sentence_tag = Color("{blue}sentences{/blue}") word_tag = Color("{blue}words{/blue}") avg_word_tag = Color("{blue}Avg words per sentence{/blue}") long_tag = Color("{red}longest{/red}") table_data = [ [Color("{autocyan}Paragraph Stats{/autocyan}")], ["Paragraph #", ""], ] for item, para in enumerate(self.article.paragraphs): sentences = (Color("{red}%s{/red}" % str(len(para))) if len(para) > 5 else str(len(para))) avg_words_per_sentence = (Color("{red}%s{/red}" % str(para.avg_words_per_sentence)) if para.avg_words_per_sentence > 25 else str(para.avg_words_per_sentence)) table_data.append([ item + 1, "{sentences} {sent_tag}. {words} {word_tag}. {avg_words} {avg_word_tag}. " '"{longest_sent}..." is the {long_tag} sentence.'.format( sentences=sentences, sent_tag=sentence_tag, words=para.total_words, word_tag=word_tag, avg_words=avg_words_per_sentence, avg_word_tag=avg_word_tag, longest_sent=str(para.longest_sentence)[0:10], long_tag=long_tag, ), ]) table_data.append([ "", "Flesh Reading score={flesch_reading}, Dale Chall Readability= {dale_chall}" .format( flesch_reading=para.get_flesch_reading_score(), dale_chall=para.get_dale_chall_reading_score(), ), ]) table_instance = SingleTable(table_data) table_instance.inner_heading_row_border = True table_instance.inner_row_border = True table_instance.justify_columns = {0: "center", 1: "left"} print(table_instance.table)
def print_lang_stat(job_site, pop_languages): if not pop_languages: return table_data = [ ['Programming language', 'Vacancies founded', 'Vacancies processed', 'Average_salary'] ] for lang, statistics in pop_languages.items(): table_data.append([lang, '{p[0]}'.format(p=statistics), '{p[1]}'.format(p=statistics), '{p[2]}'.format(p=statistics) ]) table_instance = SingleTable(table_data, job_site.capitalize()) table_instance.justify_columns = dict(zip(range(1, 4), ['right']*3)) print(table_instance.table)
def _print_deployment_summary(env): table_data = [ ["Project name:", env.project_name], ["Target:", env.target_name], ["User:"******"Host(s):", "; ".join(env.hosts)], ] table = SingleTable(table_data) table.title = Color('{autoyellow}Deployment configuration{/autoyellow}') table.justify_columns = {0: 'left', 1: 'left'} table.inner_row_border = False table.inner_heading_row_border = False _print_table(table)
def render_bank(letters=[], **kw): sz = 6 # Size of table if not any(letters): let = [' '] else: let = sorted(list(letters)) table = SingleTable([let[i:i + sz] for i in range(0, len(let), sz)], 'Incorrect Guesses') table.inner_heading_row_border = False table.inner_row_border = True table.justify_columns = { idx: val for idx, val in enumerate(['center'] * sz) } print("\n{}".format(table.table))
def do_w(self, arg): 'Show watchlist w \nAdd to watchlist w a <symbol> \nRemove from watchlist w r <symbols>' parts = re.split('\W+', arg.upper()) if len(parts) >= 2: if parts[0] == 'A': for p in parts[1:]: if p not in self.watchlist: self.watchlist.append(p.strip()) if parts[0] == 'R': self.watchlist = [ r for r in self.watchlist if r not in parts[1:] ] print("Done") else: watch_t_data = [] watch_table = SingleTable(watch_t_data, 'Watch List') watch_table.inner_row_border = True watch_table.justify_columns = { 0: 'center', 1: 'center', 2: 'center', 3: 'center', 4: 'center' } watch_t_data.append(["Symbol", "Ask Price", "Open", "Today", "%"]) if len(self.watchlist) > 0: instruments = [ self.get_instrument(s)['url'] for s in self.watchlist ] raw_data = self.trader.get_stock_marketdata(instruments) quotes_data = {} for quote in raw_data: day_change = float(quote['last_trade_price']) - float( quote['previous_close']) day_change_pct = '{:05.2f}'.format( (day_change / float(quote['previous_close'])) * 100) watch_t_data.append([ quote['symbol'], '{:05.2f}'.format(float(quote['last_trade_price'])), '{:05.2f}'.format(float(quote['previous_close'])), color_data(day_change), color_data(day_change_pct) ]) print((watch_table.table)) else: print("Watchlist empty!")
def print_article_stats(self): """This method is called to present overall article stats on a command line.""" table_data = [ [Color('{autocyan}Overall Stats{/autocyan}')], ['Reading time', str(self.article.reading_time) + ' mins'], ['Flesch Reading Ease', self.article.get_flesch_reading_score()], [ 'Dale Chall Readability Score', self.article.get_dale_chall_reading_score() ], ['Paragraphs', self.article.total_paragraphs], [ 'Avg sentences per paragraph', self.article.avg_sentences_per_para ], [ 'Total sentences in longest paragraph', self.article.len_of_longest_paragraph ], ['Sentences', self.article.total_sentences], ['Avg words per sentence', self.article.avg_words_per_sentence], [ 'Longest sentence', "%s..." % str(self.article.longest_sentence)[0:30] ], [ 'Words in longest sentence', self.article.len_of_longest_sentence ], ['Words', self.article.total_words], ['"and" frequency"', self.article.get_and_frequency()], ['Compulsive Hedgers', len(self.article.get_compulsive_hedgers())], ['Intensifiers', len(self.article.get_intensifiers())], ['Vague words', len(self.article.get_vague_words())], ] table_instance = SingleTable(table_data) table_instance.inner_heading_row_border = True table_instance.inner_row_border = True table_instance.justify_columns = {0: 'left', 1: 'center'} print(table_instance.table) self.print_detail()
def show(): """Show tasks in clikan""" config = read_config_yaml() dd = read_data(config) todos, inprogs, dones = split_items(config, dd) if 'limits' in config and 'done' in config['limits']: dones = dones[0:int(config['limits']['done'])] else: dones = dones[0:10] todos = '\n'.join([str(x) for x in todos]) inprogs = '\n'.join([str(x) for x in inprogs]) dones = '\n'.join([str(x) for x in dones]) td = [ ['todo', 'in-progress', 'done'], ['', '', ''], ] table = SingleTable(td, 'clikan') table.inner_heading_row_border = False table.inner_row_border = True table.justify_columns = {0: 'center', 1: 'center', 2: 'center'} # table.padding_left = 5 # table.padding_right = 5 def wrap_lines(lines, column_index): max_width = table.column_max_width(column_index) packed = [line for line in lines if line.strip() != ''] wrapped = [ wrap(line, max_width, break_long_words=False, replace_whitespace=False) for line in packed ] return '\n'.join(['\n'.join(w) for w in wrapped]) for index, section in enumerate((todos, inprogs, dones)): table.table_data[1][index] = wrap_lines(section.splitlines(), index) print(table.table)
def draw_grid(): table_data = [ ['00', '01', '02', '03'], ['10', '11', '12', '13'], ['20', '21', '22', '23'], ['30', '31', '32', '33'], ] table_instance = SingleTable(table_data, 'Play Game') table_instance.inner_heading_row_border = False table_instance.inner_row_border = True table_instance.justify_columns = { 0: 'center', 1: 'center', 2: 'center', 3: 'center' } print(table_instance.table)
def print_run_table(table_data): table = SingleTable(table_data) table.justify_columns = {0: 'left', 1: 'center', 2: 'left'} table.inner_heading_row_border = False table.inner_column_border = False table.outer_border = False max_width = table.column_max_width(2) for index, row in enumerate(table_data): table.table_data[index][2] = str(row[2][0:max_width].splitlines()[0]) if row[1] == 0: table.table_data[index][1] = colored(str(row[1]), 'green') elif row[1] == 1: table.table_data[index][2] = colored(str(row[1]), 'yellow') elif row[1] == 3: table.table_data[index][2] = colored(str(row[1]), 'grey') else: table.table_data[index][2] = colored(str(row[1]), 'red') print table.table
def do_status(self, line): """ Display process pool status. """ self.clean_tasks() # this prevents from re-displaying the same status table once ENTER is pressed # (marker 'restart' is handled in emptyline() hereafter if line == 'restart' and self.__last_tasklist is not None and \ hash(frozenset(self.tasklist)) == self.__last_tasklist: return self.__last_tasklist = hash(frozenset(copy(self.tasklist))) if len(self.tasklist) == 0: data = [['No task currently running']] else: data = [['Task', 'Status', 'Result']] for task, info in sorted(self.tasklist.items(), key=lambda x: str(x[0])): data.append([str(task).ljust(15), info['status'].ljust(10), str(info['result']).ljust(40)]) table = SingleTable(data, 'Status of opened tasks') table.justify_columns = {0: 'center', 1: 'center', 2: 'center'} print(table.table)
def main(): user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36' headers = { 'User-Agent' : user_agent } trackingid = raw_input("Please enter the trackingid of your UPS package : ") url1 = "https://wwwapps.ups.com/WebTracking/processRequest?HTMLVersion=5.0&Requester=NES&AgreeToTermsAndConditions=yes&loc=en_US&" url2 = "tracknum={0}".format(trackingid) if len(trackingid) < 18: print "The tracking id is wrong" url = url1 + url2 city,country,statusdate,localtime,activity = ups(url,headers) table_data = [["Tracking ID",trackingid], ["City",city], ["Country",country], ["Status Date",statusdate], ["Status Time",localtime], ["Status",activity]] table = SingleTable(table_data) table.title = "UPS Package Status" table.justify_columns = {0: 'center', 1: 'center'} table.inner_row_border = True print "" print table.table
def print_pokemon(self): sorted_mons = sorted(self.pokemon, key=lambda k: (k['pokedex_number'], -k['iv_percent'])) groups = groupby(sorted_mons, key=lambda k: k['pokedex_number']) table_data = [ [u'Pokémon', 'Level', 'CP', 'IV %', 'ATK', 'DEF', 'STA', 'Candy', 'Recommendation'] ] total_evolutions = 0 total_transfers = 0 print u'%d Pokémon found.' % len(sorted_mons) for key, group in groups: group = list(group) pokemon_name = self.pokemon_list[str(key)] best_iv_pokemon = max(group, key=lambda k: k['iv_percent']) best_iv_pokemon['best_iv'] = True candy_count=self.candy[key] result = pogotransfercalc.calculate( pokemon_count=len(group), candy_count=candy_count, pokedex_number=key) evolutions = result['evolutions'] total_evolutions += evolutions if evolutions: for pokemon in group[:evolutions]: pokemon['message'] = 'evolve' transfers = result['transfers'] transfer_count = 0 if transfers: for pokemon in reversed(group[evolutions:]): if pokemon['is_favorite']: pokemon['message'] = u'keep (★)' continue if pokemon['has_costume']: pokemon['message'] = u'keep (costume)' continue if pokemon['is_shiny']: pokemon['message'] = u'keep (shiny)' continue if pokemon['iv_percent'] < self.config.iv: pokemon['message'] = 'transfer' pokemon['transfer'] = True transfer_count += 1 total_transfers += 1 if transfer_count == transfers: break continue for pokemon in group: if pokemon['iv_percent'] >= self.config.iv: iv_msg = u'(IV ≥ %d%%)' % self.config.iv if 'message' in pokemon: pokemon['message'] += ' %s' % iv_msg else: pokemon['message'] = 'keep %s' % iv_msg row_data = [ pokemon_name + pokemon['gender'] + (u'✨' if pokemon['is_shiny'] else '') + (u'☃' if pokemon['has_costume'] else '') + (u'★' if pokemon['is_favorite'] else ''), pokemon['level'], pokemon['cp'], '{0:.0f}%'.format(pokemon['iv_percent']), pokemon['attack'], pokemon['defense'], pokemon['stamina'], candy_count, pokemon.get('message', '') ] table_data.append(row_data) table = SingleTable(table_data) table.justify_columns = { 0: 'left', 1: 'right', 2: 'right', 3: 'right', 4: 'right', 5: 'right', 6: 'right', 7: 'right' } print table.table table = SingleTable([ ['Total suggested transfers', format_number(total_transfers)], ['Total evolutions', format_number(total_evolutions)], ['Total XP from evolutions', format_number(total_evolutions * 500)], ['Total XP from evolutions with lucky egg', format_number(total_evolutions * 1000)], ]) table.inner_heading_row_border = False table.justify_columns = { 0: 'left', 1: 'right' } print table.table
def test_multi_line(): """Test multi-lined cells.""" table_data = [ ['Show', 'Characters'], ['Rugrats', 'Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles,\nDil Pickles'], ['South Park', 'Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick'] ] table = SingleTable(table_data) # Test defaults. actual = table.table expected = ( '\033(0\x6c\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x77\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6b\033(B\n' '\033(0\x78\033(B Show \033(0\x78\033(B Characters ' ' \033(0\x78\033(B\n' '\033(0\x74\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6e\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x75\033(B\n' '\033(0\x78\033(B Rugrats \033(0\x78\033(B Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille,' ' Angelica Pickles, \033(0\x78\033(B\n' '\033(0\x78\033(B \033(0\x78\033(B Dil Pickles ' ' \033(0\x78\033(B\n' '\033(0\x78\033(B South Park \033(0\x78\033(B Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick ' ' \033(0\x78\033(B\n' '\033(0\x6d\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x76\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6a\033(B' ) assert actual == expected # Test inner row border. table.inner_row_border = True actual = table.table expected = ( '\033(0\x6c\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x77\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6b\033(B\n' '\033(0\x78\033(B Show \033(0\x78\033(B Characters ' ' \033(0\x78\033(B\n' '\033(0\x74\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6e\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x75\033(B\n' '\033(0\x78\033(B Rugrats \033(0\x78\033(B Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille,' ' Angelica Pickles, \033(0\x78\033(B\n' '\033(0\x78\033(B \033(0\x78\033(B Dil Pickles ' ' \033(0\x78\033(B\n' '\033(0\x74\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6e\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x75\033(B\n' '\033(0\x78\033(B South Park \033(0\x78\033(B Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick ' ' \033(0\x78\033(B\n' '\033(0\x6d\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x76\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6a\033(B' ) assert actual == expected # Justify right. table.justify_columns = {1: 'right'} actual = table.table expected = ( '\033(0\x6c\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x77\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6b\033(B\n' '\033(0\x78\033(B Show \033(0\x78\033(B ' ' Characters \033(0\x78\033(B\n' '\033(0\x74\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6e\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x75\033(B\n' '\033(0\x78\033(B Rugrats \033(0\x78\033(B Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille,' ' Angelica Pickles, \033(0\x78\033(B\n' '\033(0\x78\033(B \033(0\x78\033(B ' ' Dil Pickles \033(0\x78\033(B\n' '\033(0\x74\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6e\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x75\033(B\n' '\033(0\x78\033(B South Park \033(0\x78\033(B Stan Marsh, Kyle Broflovski, ' 'Eric Cartman, Kenny McCormick \033(0\x78\033(B\n' '\033(0\x6d\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x76\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71' '\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x71\x6a\033(B' ) assert actual == expected
def test_multi_line(): """Test multi-lined cells.""" table_data = [ ['Show', 'Characters'], ['Rugrats', 'Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles,\nDil Pickles'], ['South Park', 'Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick'] ] table = SingleTable(table_data) # Test defaults. actual = table.table expected = ( u'\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n' u'\u2502 Show \u2502 Characters ' u'\u2502\n' u'\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n' u'\u2502 Rugrats \u2502 Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, ' u'\u2502\n' u'\u2502 \u2502 Dil Pickles ' u'\u2502\n' u'\u2502 South Park \u2502 Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick ' u'\u2502\n' u'\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518' ) assert actual == expected # Test inner row border. table.inner_row_border = True actual = table.table expected = ( u'\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n' u'\u2502 Show \u2502 Characters ' u'\u2502\n' u'\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n' u'\u2502 Rugrats \u2502 Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, ' u'\u2502\n' u'\u2502 \u2502 Dil Pickles ' u'\u2502\n' u'\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n' u'\u2502 South Park \u2502 Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick ' u'\u2502\n' u'\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518' ) assert actual == expected # Justify right. table.justify_columns = {1: 'right'} actual = table.table expected = ( u'\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n' u'\u2502 Show \u2502 Characters ' u'\u2502\n' u'\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n' u'\u2502 Rugrats \u2502 Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, ' u'\u2502\n' u'\u2502 \u2502 Dil Pickles ' u'\u2502\n' u'\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n' u'\u2502 South Park \u2502 Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick ' u'\u2502\n' u'\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' u'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518' ) assert actual == expected
Windows.enable(auto_colors=True, reset_atexit=True) # Does nothing if not on Windows. table_data = [ [Color('{autobgred}{autogreen}<10ms{/autogreen}{/bgred}'), '192.168.0.100, 192.168.0.101'], [Color('{autoyellow}10ms <= 100ms{/autoyellow}'), '192.168.0.102, 192.168.0.103'], [Color('{autored}>100ms{/autored}'), '192.168.0.105'], ] table = SingleTable(table_data) table.inner_heading_row_border = False print() print(table.table) table.title = '192.168.0.105' table.justify_columns = {0: 'center', 1: 'center', 2: 'center'} table.inner_row_border = True table.table_data = [ [Color('Low Space'), Color('{autocyan}Nominal Space{/autocyan}'), Color('Excessive Space')], [Color('Low Load'), Color('Nominal Load'), Color('{autored}High Load{/autored}')], [Color('{autocyan}Low Free RAM{/autocyan}'), Color('Nominal Free RAM'), Color('High Free RAM')], ] print() print(table.table) table.title = None table.outer_border = False table.table_data = [['A', 'B'], ['C', 'D']] print() print(table.table)