Eren Yilmaz преди 6 години
родител
ревизия
88bd0315c2
променени са 2 файла, в които са добавени 37 реда и са изтрити 34 реда
  1. 27 34
      client_controller.py
  2. 10 0
      util.py

+ 27 - 34
client_controller.py

@@ -5,9 +5,9 @@ from inspect import signature
 import connection
 from run_client import allowed_commands, fake_loading_bar
 from connection import client_request
-import tabulate
 
 from debug import debug
+from util import my_tabulate
 
 exiting = False
 
@@ -134,13 +134,13 @@ def help():
         params = signature(method).parameters
         command_table.append([cmd] + [p for p in params])
 
-    print(_my_tabulate(command_table, tablefmt='pipe', headers=['command',
-                                                                'param 1',
-                                                                'param 2',
-                                                                'param 3',
-                                                                'param 4',
-                                                                'param 5',
-                                                                ]))
+    print(my_tabulate(command_table, tablefmt='pipe', headers=['command',
+                                                               'param 1',
+                                                               'param 2',
+                                                               'param 3',
+                                                               'param 4',
+                                                               'param 5',
+                                                               ]))
     print('NOTE:')
     print('  All parameters for all commands are optional!')
     print('  Commands can be combined in one line with ; between them.')
@@ -149,13 +149,6 @@ def help():
     print('  Use 0/1 for boolean parameters (other strings might work).')
 
 
-def _my_tabulate(data, **params):
-    if data == [] and 'headers' in params:
-        data = [(None for _ in params['headers'])]
-    tabulate.MIN_PADDING = 0
-    return tabulate.tabulate(data, **params)
-
-
 def depot():
     fake_loading_bar('Loading data', duration=1.3)
     response = client_request('depot', {"session_id": connection.session_id})
@@ -164,9 +157,9 @@ def depot():
         data = response['data']
         for row in data:
             row.append(row[1] * row[2])
-        print(_my_tabulate(data,
-                           headers=['Object', 'Amount', 'Course', 'Bid', 'Ask', 'Est. Value'],
-                           tablefmt="pipe"))
+        print(my_tabulate(data,
+                          headers=['Object', 'Amount', 'Course', 'Bid', 'Ask', 'Est. Value'],
+                          tablefmt="pipe"))
         print('This corresponds to a wealth of roughly', response['own_wealth'])
     else:
         if 'error_message' in response:
@@ -180,7 +173,7 @@ def leaderboard():
     response = client_request('leaderboard', {})
     success = 'data' in response
     if success:
-        print(_my_tabulate(response['data'], headers=['Trader', 'Wealth'], tablefmt="pipe"))
+        print(my_tabulate(response['data'], headers=['Trader', 'Wealth'], tablefmt="pipe"))
         # print('Remember that the goal is to be as rich as possible, not to be richer than other traders!')
     else:
         if 'error_message' in response:
@@ -312,9 +305,9 @@ def orders():
     response = client_request('orders', {"session_id": connection.session_id})
     success = 'data' in response
     if success:
-        print(_my_tabulate(response['data'],
-                           headers=['Buy?', 'Name', 'Size', 'Limit', 'stop-loss', 'Expires', 'No.'],
-                           tablefmt="pipe"))
+        print(my_tabulate(response['data'],
+                          headers=['Buy?', 'Name', 'Size', 'Limit', 'stop-loss', 'Expires', 'No.'],
+                          tablefmt="pipe"))
     else:
         if 'error_message' in response:
             print('Order access failed with message:', response['error_message'])
@@ -329,9 +322,9 @@ def orders_on(obj_name=None):
     response = client_request('orders_on', {"session_id": connection.session_id, "ownable": obj_name})
     success = 'data' in response
     if success:
-        print(_my_tabulate(response['data'],
-                           headers=['My', 'Buy?', 'Name', 'Size', 'Limit', 'Expires', 'No.'],
-                           tablefmt="pipe"))
+        print(my_tabulate(response['data'],
+                          headers=['My', 'Buy?', 'Name', 'Size', 'Limit', 'Expires', 'No.'],
+                          tablefmt="pipe"))
     else:
         if 'error_message' in response:
             print('Order access failed with message:', response['error_message'])
@@ -363,9 +356,9 @@ def news():
     response = client_request('news', {})
     success = 'data' in response
     if success:
-        print(_my_tabulate(response['data'],
-                           headers=['Date', 'Title'],
-                           tablefmt="pipe"))
+        print(my_tabulate(response['data'],
+                          headers=['Date', 'Title'],
+                          tablefmt="pipe"))
     else:
         if 'error_message' in response:
             print('News access failed with message:', response['error_message'])
@@ -378,9 +371,9 @@ def tradables():
     response = client_request('tradables', {})
     success = 'data' in response
     if success:
-        print(_my_tabulate(response['data'],
-                           headers=['Name', 'Course', 'Market Cap.'],
-                           tablefmt="pipe"))
+        print(my_tabulate(response['data'],
+                          headers=['Name', 'Course', 'Market Cap.'],
+                          tablefmt="pipe"))
         world_wealth = 0
         for row in response['data']:
             if row[2] is not None:
@@ -404,9 +397,9 @@ def transactions(obj_name=None, limit=5):
                                                "limit": limit})
     success = 'data' in response
     if success:
-        print(_my_tabulate(response['data'],
-                           headers=['Time', 'Volume', 'Price'],
-                           tablefmt="pipe"))
+        print(my_tabulate(response['data'],
+                          headers=['Time', 'Volume', 'Price'],
+                          tablefmt="pipe"))
     else:
         if 'error_message' in response:
             print('Transactions access failed with message:', response['error_message'])

+ 10 - 0
util.py

@@ -1,5 +1,8 @@
 from random import random
 
+import tabulate
+
+# noinspection SpellCheckingInspection
 salt = 'orderer_is_a_cool_application_]{][{²$%WT§$%GV§$%SF$%&S$%FGGFHBDHJZIF254325'
 
 chars = [str(d) for d in range(1, 10)]
@@ -40,3 +43,10 @@ def str2bool(v):
     if v in ["no", 'n' "false", "f", "0", '', 'null', 'none']:
         return False
     raise ValueError('Can not convert `' + v + '` to bool')
+
+
+def my_tabulate(data, **params):
+    if data == [] and 'headers' in params:
+        data = [(None for _ in params['headers'])]
+    tabulate.MIN_PADDING = 0
+    return tabulate.tabulate(data, **params)