Browse Source

exit command

Eren Yilmaz 6 years ago
parent
commit
d8aa442f9b
3 changed files with 18 additions and 4 deletions
  1. 9 0
      client_controller.py
  2. 8 3
      run_client.py
  3. 1 1
      util.py

+ 9 - 0
client_controller.py

@@ -10,6 +10,9 @@ from tabulate import tabulate
 from util import debug
 
 
+exiting = False
+
+
 def login(username=None, password=None):
     if connection.session_id is not None:
         fake_loading_bar('Signing out', duration=0.7)
@@ -273,3 +276,9 @@ def transactions(object_name=None):
             print('Transactions access failed with message:', response['error_message'])
         else:
             print('Transactions access failed.')
+
+
+# noinspection PyShadowingBuiltins
+def exit():
+    global exiting
+    exiting = True

+ 8 - 3
run_client.py

@@ -64,7 +64,8 @@ allowed_commands = ['help',
                     'transactions',
                     'orders_on',
                     'cancel_order',
-                    'leaderboard']
+                    'leaderboard',
+                    'exit']
 
 
 def one_command():
@@ -89,9 +90,13 @@ def one_command():
                 print('An error occurred while executing a command.')
 
 
+def exit_client():
+    global exiting
+    exiting = True
+
+
 if __name__ == '__main__':
     load()
     welcome()
-
-    while True:
+    while not client_controller.exiting:
         one_command()

+ 1 - 1
util.py

@@ -1,6 +1,6 @@
 from random import random
 
-debug = True
+debug = __debug__
 chars = [str(d) for d in range(1, 10)]
 
 ps = [1. for _ in chars]