import sys import time import client_controller from util import debug def fake_loading_bar(msg, delay=0.100): if len(msg) >= 32: raise AssertionError('Loading bar label too large') msg += ': ' print(msg, end='') sys.stdout.flush() for _ in range(78 - len(msg)): if not debug: time.sleep(delay) print('#', end='') sys.stdout.flush() print('\n', end='') sys.stdout.flush() def load(): print('Loading...') fake_loading_bar('Initializing fake loading bars') fake_loading_bar('Loading data from disk') fake_loading_bar('Loading available commands') fake_loading_bar('Updating indices') fake_loading_bar('Waiting') print('Done.\n\n') def welcome(): print(''' $$$$$$\ $$\ $$ __$$\ $$ | $$ / $$ | $$$$$$\ $$$$$$$ | $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$ | $$ |$$ __$$\ $$ __$$ |$$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\ $$ | $$ |$$ | \__|$$ / $$ |$$$$$$$$ |$$ | \__|$$$$$$$$ |$$ | \__| $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ ____|$$ | $$$$$$ |$$ | \$$$$$$$ |\$$$$$$$\ $$ | \$$$$$$$\ $$ | \______/ \__| \_______| \_______|\__| \_______|\__| To display an overview of available commands type \'help\'. ''') allowed_commands = ['help', 'login', 'register', 'depot', 'orders', 'news', 'activate_key', 'buy', 'sell', 'transactions', 'orders_on'] def one_command(): cmd = input('*> ').strip() cmds = cmd.split(';') for cmd in cmds: cmd = cmd.split() # cmd = [cmd.strip() for cmd in cmd] # noinspection PySimplifyBooleanCheck if cmd == []: continue if cmd[0] not in allowed_commands: print('Invalid command:', cmd[0]) else: method_to_call = getattr(client_controller, cmd[0]) # noinspection PyBroadException try: method_to_call(*cmd[1:]) except TypeError: print('Invalid command syntax.') except Exception: print('An error occurred while executing a command.') if __name__ == '__main__': load() welcome() while True: one_command()