from __future__ import print_function import sys import time import client_controller from debug import debug def fake_loading_bar(msg, duration=5.): if len(msg) >= 60: raise AssertionError('Loading bar label too large') msg += ': ' print(msg, end='') sys.stdout.flush() bar_length = 79 - len(msg) for _ in range(bar_length): if not debug: time.sleep(duration / bar_length) print('#', end='') sys.stdout.flush() print('\n', end='') sys.stdout.flush() def load(): print('Loading...') fake_loading_bar('Initializing fake loading bars', duration=5) fake_loading_bar('Loading data from disk', duration=1) fake_loading_bar('Loading available commands', duration=3.5) fake_loading_bar('Updating indices', duration=2) fake_loading_bar('Waiting', duration=5) print('Done.\n\n') def welcome(): print(''' $$$$$$\ $$\ $$ __$$\ $$ | $$ / $$ | $$$$$$\ $$$$$$$ | $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$ | $$ |$$ __$$\ $$ __$$ |$$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\ $$ | $$ |$$ | \__|$$ / $$ |$$$$$$$$ |$$ | \__|$$$$$$$$ |$$ | \__| $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ ____|$$ | $$$$$$ |$$ | \$$$$$$$ |\$$$$$$$\ $$ | \$$$$$$$\ $$ | \______/ \__| \_______| \_______|\__| \_______|\__| To display an overview of available commands type \'help\'. ''') allowed_commands = ['help', 'login', 'register', 'change_pw', 'news', 'tradables', 'depot', 'orders', 'activate_key', 'buy', 'sell', 'transactions', 'orders_on', 'cancel_order', 'gift', 'leaderboard', 'exit'] 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 cmd[0] = cmd[0].lower() 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.') def exit_client(): global exiting exiting = True if __name__ == '__main__': load() welcome() while not client_controller.exiting: one_command()