123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- from __future__ import print_function
- import sys
- import time
- import client_controller
- from debug import debug
- from util import yn_dialog
- 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(r'''
- $$$$$$\ $$\
- $$ __$$\ $$ |
- $$ / $$ | $$$$$$\ $$$$$$$ | $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\
- $$ | $$ |$$ __$$\ $$ __$$ |$$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\
- $$ | $$ |$$ | \__|$$ / $$ |$$$$$$$$ |$$ | \__|$$$$$$$$ |$$ | \__|
- $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ ____|$$ |
- $$$$$$ |$$ | \$$$$$$$ |\$$$$$$$\ $$ | \$$$$$$$\ $$ |
- \______/ \__| \_______| \_______|\__| \_______|\__|
-
-
-
- To display an overview of available commands type \'help\'.
- ''')
- allowed_commands = ['help',
- 'login',
- 'register',
- 'change_pw',
- 'news',
- 'tradables',
- 'depot',
- 'orders',
- 'orders_on',
- 'old_orders',
- 'trades',
- 'trades_on',
- 'buy',
- 'sell',
- 'cancel_order',
- 'gift',
- 'leaderboard',
- 'activate_key',
- 'exit']
- def one_command():
- try:
- cmd = input('*> ').strip()
- except KeyboardInterrupt:
- if yn_dialog('Do you want to exit Orderer?'):
- print('Then type in `exit` :P')
- return
- else:
- return
- 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 ConnectionError:
- print('There has been a problem connecting when to the server.')
- except KeyboardInterrupt:
- print('Interrupted')
- except Exception as _:
- print('An unknown error occurred while executing a command.')
- if __name__ == '__main__':
- load()
- welcome()
- while not client_controller.exiting:
- one_command()
|