Ver código fonte

cleaning code

serinko 4 anos atrás
pai
commit
a7383b544b
2 arquivos alterados com 27 adições e 108 exclusões
  1. 12 38
      texts_cli.py
  2. 15 70
      whallets_cli.py

+ 12 - 38
texts_cli.py

@@ -1,6 +1,4 @@
 """A module with all the display info for whallets-cli."""
 """A module with all the display info for whallets-cli."""
-from tabulate import tabulate
-
 
 
 def _welcome_message():
 def _welcome_message():
     """welcoming message to the cli"""
     """welcoming message to the cli"""
@@ -10,6 +8,7 @@ def _welcome_message():
         "\n========================================="
         "\n========================================="
     return msg
     return msg
 
 
+
 def _main_menu():
 def _main_menu():
     """Displays the CLI main menu"""
     """Displays the CLI main menu"""
     line_0 = ("**","MAIN MENU:")
     line_0 = ("**","MAIN MENU:")
@@ -35,17 +34,20 @@ def _main_menu():
     ]
     ]
     return table
     return table
 
 
+
 def _menu_choice():
 def _menu_choice():
     """Sentence asking user for the next step"""
     """Sentence asking user for the next step"""
     msg = "\nEnter number and press Enter: "
     msg = "\nEnter number and press Enter: "
     return msg
     return msg
 
 
+
 def _missing_operation():
 def _missing_operation():
     """Inform about non-existing users choice"""
     """Inform about non-existing users choice"""
     msg = "\nSorry, but you had either choosen an unexisting option, "\
     msg = "\nSorry, but you had either choosen an unexisting option, "\
     "or this operation has not been developped yet."
     "or this operation has not been developped yet."
     return msg
     return msg
 
 
+
 def _ask_new_choice():
 def _ask_new_choice():
     """Message offering a new choice or quit"""
     """Message offering a new choice or quit"""
     msg = \
     msg = \
@@ -54,7 +56,6 @@ def _ask_new_choice():
     return msg
     return msg
 
 
 
 
-
 def _choose_network():
 def _choose_network():
     """Gives a choice of networks to work with"""
     """Gives a choice of networks to work with"""
     line_0 = ("**","Please chose the network for the wallet address:")
     line_0 = ("**","Please chose the network for the wallet address:")
@@ -65,11 +66,13 @@ def _choose_network():
     table = [ line_0, line, line_1, line_2, line_3]
     table = [ line_0, line, line_1, line_2, line_3]
     return table
     return table
 
 
+
 def _prompt_new_info(item):
 def _prompt_new_info(item):
     """Ask or the wallet address"""
     """Ask or the wallet address"""
     msg = f"\nEnter the wallet {item}:\n(if unknown press Enter)\n"
     msg = f"\nEnter the wallet {item}:\n(if unknown press Enter)\n"
     return msg
     return msg
 
 
+
 def _ask_more_wallets():
 def _ask_more_wallets():
     """ask user if an account has more wallet addresses"""
     """ask user if an account has more wallet addresses"""
     msg_0 = \
     msg_0 = \
@@ -80,28 +83,6 @@ def _ask_more_wallets():
     return msg_0, msg_1
     return msg_0, msg_1
 
 
 
 
-
-# def _prompt_twitter():
-#     """Ask or the wallet address"""
-#     msg = "\nEnter the twitter link (full address):\n"
-#     return msg
-#
-# def _prompt_info():
-#     """Ask or the wallet address"""
-#     msg = "\nEnter short info about the user:\n"
-#     return msg
-#
-# def _prompt_name():
-#     """Ask or the wallet address"""
-#     msg = "\nEnter user/wallet name/tag:\n"
-#     return msg
-#
-# def _prompt_ens():
-#     """Ask or the wallet address"""
-#     msg = "\nEnter user's ENS:\n"
-#     return msg
-
-
 def _display_wallet_check_result(key):
 def _display_wallet_check_result(key):
     """displays answer based on added data"""
     """displays answer based on added data"""
     msg_0 = \
     msg_0 = \
@@ -166,26 +147,19 @@ def _confirm_entry():
     return msg_0, msg_1, msg_2
     return msg_0, msg_1, msg_2
 
 
 
 
-def _display_database(i, user, info, twitter,):
+def _table_headers():
     """Text template for table of wallet display function"""
     """Text template for table of wallet display function"""
-    line_0 = ("#","USER","TWITTER","ENS","INFO","ADDRESSES","NETWORKS")
-    line = ("==","=======","===========","===========",
-            "===========","===========","===========")
-
+    line_0 = [
+        "#", "USER", "ENS", "TWITTER", "INFO", "ADDRESSES", "NETWORKS"]
+    line_ = ["==", "=========", "===========", "===========",
+             "===========", "===========", "==========="]
+    return line_0, line_
 
 
 def _csv_exported():
 def _csv_exported():
     """displays information about csv stored"""
     """displays information about csv stored"""
     msg = "\nThe wallet database was exported to ~/whallets/data/whallets.csv."
     msg = "\nThe wallet database was exported to ~/whallets/data/whallets.csv."
     return msg
     return msg
 
 
-
-
-
-#     line_0 = ("*****",f"{chain.upper} WALLETS")
-#     line = ("=====================================================",)
-#     line_1 = ("Username:",f"{user}")
-
-
 def _return_network(ntw_i):
 def _return_network(ntw_i):
     """Return network based on index"""
     """Return network based on index"""
     if ntw_i == 0:
     if ntw_i == 0:

+ 15 - 70
whallets_cli.py

@@ -15,15 +15,13 @@ from tabulate import tabulate
 import texts_cli as tc
 import texts_cli as tc
 import csv
 import csv
 
 
-print(tc._welcome_message())
 
 
 def cli_main():
 def cli_main():
     """Main program for the cli"""
     """Main program for the cli"""
-
-
     print(tabulate(tc._main_menu()))
     print(tabulate(tc._main_menu()))
     main_menu_choice()
     main_menu_choice()
 
 
+
 def main_menu_choice():
 def main_menu_choice():
     """main cli operations choice"""
     """main cli operations choice"""
     choice = input(tc._menu_choice())
     choice = input(tc._menu_choice())
@@ -51,9 +49,9 @@ def main_menu_choice():
 
 
     _new_choice()
     _new_choice()
 
 
+
 def _new_choice():
 def _new_choice():
     """Offer user a new choice"""
     """Offer user a new choice"""
-
     x = 1
     x = 1
     while x < 3:
     while x < 3:
         chc = input(tc._ask_new_choice())
         chc = input(tc._ask_new_choice())
@@ -66,22 +64,18 @@ def _new_choice():
     else:
     else:
         quit()
         quit()
 
 
+
 def add_wallet():
 def add_wallet():
     """A function to add wallet to the wallets_dict.json"""
     """A function to add wallet to the wallets_dict.json"""
     new_wallet, addresses, ntw_i = get_inputs()
     new_wallet, addresses, ntw_i = get_inputs()
-
-
     print(tabulate(tc._save_wallet_confirm(addresses, new_wallet)))
     print(tabulate(tc._save_wallet_confirm(addresses, new_wallet)))
     confirm_entry(ntw_i, addresses, new_wallet)
     confirm_entry(ntw_i, addresses, new_wallet)
 
 
 
 
-
 def confirm_entry(ntw_i, addresses, new_wallet):
 def confirm_entry(ntw_i, addresses, new_wallet):
     """Preview the new wallet and confirm saving it"""
     """Preview the new wallet and confirm saving it"""
     x = input(tc._confirm_entry()[0])
     x = input(tc._confirm_entry()[0])
     if x == '1':
     if x == '1':
-        # new_wallet_dict = refactor_wallet(addresses, **new_wallet)
-        # save_wallet(**new_wallet_dict)
         print(tc._confirm_entry()[1])
         print(tc._confirm_entry()[1])
         new_wallet_dictionary = refactor_wallet(addresses, new_wallet)
         new_wallet_dictionary = refactor_wallet(addresses, new_wallet)
         save_wallet(ntw_i, new_wallet_dictionary)
         save_wallet(ntw_i, new_wallet_dictionary)
@@ -93,11 +87,8 @@ def confirm_entry(ntw_i, addresses, new_wallet):
         add_wallet()
         add_wallet()
 
 
 
 
-
-
 def save_wallet(ntw_i, new_wallet_dictionary):
 def save_wallet(ntw_i, new_wallet_dictionary):
     """Saves the wallet into the database/dictionary and informs the user"""
     """Saves the wallet into the database/dictionary and informs the user"""
-   
     filename = 'wallets_dict.json'
     filename = 'wallets_dict.json'
 
 
     with open(filename) as f:
     with open(filename) as f:
@@ -114,7 +105,6 @@ def save_wallet(ntw_i, new_wallet_dictionary):
         json.dump(all_wallets,f, indent=4)
         json.dump(all_wallets,f, indent=4)
 
 
 
 
-
 def refactor_wallet(addresses, new_wallet):
 def refactor_wallet(addresses, new_wallet):
     """Refactor the wallet items to the wallet_dict format"""
     """Refactor the wallet items to the wallet_dict format"""
     username = new_wallet["username"]
     username = new_wallet["username"]
@@ -135,19 +125,20 @@ def refactor_wallet(addresses, new_wallet):
             "address":f"{addr}",
             "address":f"{addr}",
             "networks":[
             "networks":[
                 "erc"
                 "erc"
-                # need to add a code how to add networks
+                # need to add a code how to add networks automatically
                 ]
                 ]
             }
             }
         }
         }
         new_wallet_dictionary[username]["wallets"].update(wallet)
         new_wallet_dictionary[username]["wallets"].update(wallet)
-    # print(f"\n\n\n{new_wallet_dictionary}")
 
 
     return new_wallet_dictionary
     return new_wallet_dictionary
 
 
+
 def remove_wallet():
 def remove_wallet():
     """Removes wallet from the wallet dictionary"""
     """Removes wallet from the wallet dictionary"""
     # This function needs to be developed
     # This function needs to be developed
 
 
+
 def get_inputs():
 def get_inputs():
     """Get infor to add a new wallet"""
     """Get infor to add a new wallet"""
     ntw_i = _check_network()
     ntw_i = _check_network()
@@ -178,6 +169,7 @@ def get_inputs():
 
 
     return new_wallet, addresses, ntw_i
     return new_wallet, addresses, ntw_i
 
 
+
 def check_wallet_item(ntw_i,x,key,):
 def check_wallet_item(ntw_i,x,key,):
     """
     """
     Scans through wallets to check if a new wallet is not already in the
     Scans through wallets to check if a new wallet is not already in the
@@ -204,31 +196,9 @@ def check_wallet_item(ntw_i,x,key,):
 
 
     return new_item
     return new_item
 
 
-        # username = key
-        # wallets = value['wallets']
-        # info = value['info']
-        # twitter = value['twitter']
-        # ens_saved = value['ens']
-
-
-
-
-    #
-    #     if x == username:
-    #         new_item = _correct_item(x,'username')
-    #     elif x in wallets.values():
-    #         new_item = _correct_item(x,'wallet address')
-    #     elif x == twitter:
-    #         new_item = _correct_item(x,'twitter address')
-    #     elif x == ens_saved:
-    #         new_item = _correct_item(x, 'ENS')
-    #     else:
-    #         new_item = x
-
 
 
 def _correct_item(x,key):
 def _correct_item(x,key):
     """Allows user to rewrite an exisitng item in the wallet"""
     """Allows user to rewrite an exisitng item in the wallet"""
-
     choice = input(tc._display_wallet_check_result(key)[0])
     choice = input(tc._display_wallet_check_result(key)[0])
 
 
     if choice == '1':
     if choice == '1':
@@ -251,6 +221,7 @@ def _check_network():
     else:
     else:
         return i
         return i
 
 
+
 def get_wallets():
 def get_wallets():
     """ Gets the info from the dictionary """
     """ Gets the info from the dictionary """
     filename = 'wallets_dict.json'
     filename = 'wallets_dict.json'
@@ -270,39 +241,10 @@ def table_format_wallets(chain):
     dict = get_wallets()[i]
     dict = get_wallets()[i]
     print(f"\n\n{chain.upper()} WALLETS:")
     print(f"\n\n{chain.upper()} WALLETS:")
 
 
-    # for key, value in dict.items():
-    #     user = key
-    #     info = value['info']
-    #     twitter = value['twitter']
-    #     ens = value['ens']
-    #     wallets = {}
-    #     wlts = value['wallets']
-    #     for x, y in wlts.items():
-    #         wallets[x] = y
-    #
-    #
-    #     print(f"\nUser: {user}")
-    #     print(f"Info: {info}")
-    #     print(f"Twitter: {twitter}")
-    #     for wlt,inf in wallets.items():
-    #         print(f"Wallets: {wlt}")
-    #         print(f"Address: {inf['address']}")
-    #         print(f"Active networks:")
-    #         networks = inf['networks']
-    #         networks_str = ', '.join(networks)
-    #         print(networks_str)
-
-    # table = []
-    line_0 = [
-    "#", "USER", "ENS", "TWITTER", "INFO", "ADDRESSES", "NETWORKS"]
-    line_ = ["==", "=========", "===========", "===========",
-            "===========", "===========", "==========="]
+    line_0, line_ = tc._table_headers()
     table = [line_0, line_,]
     table = [line_0, line_,]
 
 
-
-
     for i, (key, value) in enumerate(dict.items()):
     for i, (key, value) in enumerate(dict.items()):
-
         index = i + 1
         index = i + 1
         user = key
         user = key
         info = value['info']
         info = value['info']
@@ -310,6 +252,7 @@ def table_format_wallets(chain):
         ens = value['ens']
         ens = value['ens']
         wallets = {}
         wallets = {}
         wlts = value['wallets']
         wlts = value['wallets']
+
         for x, y in wlts.items():
         for x, y in wlts.items():
             wallets[x] = y
             wallets[x] = y
 
 
@@ -331,9 +274,10 @@ def table_format_wallets(chain):
 
 
     return table
     return table
 
 
+
 def csv_export():
 def csv_export():
     """Exports the wallets to csv files"""
     """Exports the wallets to csv files"""
-    # Need to add SPL wallets when they are relevant
+    # Need to add SPL & BTC wallet option when relevant
     table = table_format_wallets('evm')
     table = table_format_wallets('evm')
     del table[1]
     del table[1]
     file = 'data/whallets.csv'
     file = 'data/whallets.csv'
@@ -352,13 +296,13 @@ def _chain_index(chain):
         i = 1
         i = 1
     return i
     return i
 
 
+
 def display_wallets(chain):
 def display_wallets(chain):
     """Displays the wallets according the given chain"""
     """Displays the wallets according the given chain"""
     table = table_format_wallets(chain)
     table = table_format_wallets(chain)
     print(tabulate(table))
     print(tabulate(table))
 
 
 
 
-
 def display_all_wallets():
 def display_all_wallets():
     display_wallets('evm')
     display_wallets('evm')
     display_wallets('spl')
     display_wallets('spl')
@@ -366,4 +310,5 @@ def display_all_wallets():
 
 
 # Run the program
 # Run the program
 if __name__ == '__main__':
 if __name__ == '__main__':
-    cli_main()
+    print(tc._welcome_message())
+    cli_main()