From a06439c13650cbbe03d19fef792e0fc3d099e618 Mon Sep 17 00:00:00 2001 From: "didierlopes.eth" Date: Tue, 15 Mar 2022 09:45:57 +0000 Subject: [PATCH] add links to get API keys when no args provided and fix bugs (#1486) --- gamestonk_terminal/keys_controller.py | 120 ++++++++++++++++++++++---- 1 file changed, 103 insertions(+), 17 deletions(-) diff --git a/gamestonk_terminal/keys_controller.py b/gamestonk_terminal/keys_controller.py index b28633e0845..7750d9979cb 100644 --- a/gamestonk_terminal/keys_controller.py +++ b/gamestonk_terminal/keys_controller.py @@ -332,19 +332,20 @@ class KeysController(BaseController): logger.info("Reddit key not defined") self.key_dict["REDDIT"] = "not defined" else: - praw_api = praw.Reddit( - client_id=cfg.API_REDDIT_CLIENT_ID, - client_secret=cfg.API_REDDIT_CLIENT_SECRET, - username=cfg.API_REDDIT_USERNAME, - user_agent=cfg.API_REDDIT_USER_AGENT, - password=cfg.API_REDDIT_PASSWORD, - ) try: + praw_api = praw.Reddit( + client_id=cfg.API_REDDIT_CLIENT_ID, + client_secret=cfg.API_REDDIT_CLIENT_SECRET, + username=cfg.API_REDDIT_USERNAME, + user_agent=cfg.API_REDDIT_USER_AGENT, + password=cfg.API_REDDIT_PASSWORD, + ) + praw_api.user.me() logger.info("Reddit key defined, test passed") self.key_dict["REDDIT"] = "defined, test passed" - except ResponseException: + except (Exception, ResponseException): logger.warning("Reddit key defined, test passed") self.key_dict["REDDIT"] = "defined, test failed" @@ -737,6 +738,12 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print( + "For your API Key, visit: https://www.alphavantage.co/support/#api-key\n" + ) + return + if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -762,6 +769,12 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print( + "For your API Key, visit: https://financialmodelingprep.com\n" + ) + return + if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -789,6 +802,10 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://www.quandl.com\n") + return + if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -814,6 +831,10 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://polygon.io\n") + return + if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -839,6 +860,10 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://fred.stlouisfed.org\n") + return + if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -864,6 +889,10 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://newsapi.org\n") + return + if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -889,6 +918,10 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://developer.tradier.com\n") + return + if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -914,6 +947,9 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://coinmarketcap.com\n") + return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -939,6 +975,9 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://finnhub.io\n") + return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -964,6 +1003,9 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://iexcloud.io\n") + return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -1017,6 +1059,9 @@ class KeysController(BaseController): dest="user_agent", help="User agent", ) + if not other_args: + console.print("For your API Key, visit: https://www.reddit.com\n") + return ns_parser = parse_known_args_and_warn(parser, other_args) if ns_parser: os.environ["GT_API_REDDIT_CLIENT_ID"] = ns_parser.client_id @@ -1077,6 +1122,9 @@ class KeysController(BaseController): dest="bearer_token", help="Bearer token", ) + if not other_args: + console.print("For your API Key, visit: https://developer.twitter.com\n") + return ns_parser = parse_known_args_and_warn(parser, other_args) if ns_parser: os.environ["GT_API_TWITTER_KEY"] = ns_parser.key @@ -1120,6 +1168,9 @@ class KeysController(BaseController): dest="password", help="password", ) + if not other_args: + console.print("For your API Key, visit: https://robinhood.com/us/en/\n") + return ns_parser = parse_known_args_and_warn(parser, other_args) if ns_parser: os.environ["GT_RH_USERNAME"] = ns_parser.username @@ -1162,6 +1213,9 @@ class KeysController(BaseController): dest="secret", help="TOPT Secret", ) + if not other_args: + console.print("For your API Key, visit: https://www.degiro.fr\n") + return ns_parser = parse_known_args_and_warn(parser, other_args) if ns_parser: os.environ["GT_DG_USERNAME"] = ns_parser.username @@ -1208,6 +1262,9 @@ class KeysController(BaseController): dest="account_type", help="account type", ) + if not other_args: + console.print("For your API Key, visit: https://developer.oanda.com\n") + return ns_parser = parse_known_args_and_warn(parser, other_args) if ns_parser: os.environ["GT_OANDA_ACCOUNT"] = ns_parser.account @@ -1249,6 +1306,9 @@ class KeysController(BaseController): dest="secret_key", help="Secret key", ) + if not other_args: + console.print("For your API Key, visit: https://binance.com\n") + return ns_parser = parse_known_args_and_warn(parser, other_args) if ns_parser: os.environ["GT_API_BINANCE_KEY"] = ns_parser.key @@ -1277,6 +1337,9 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://bitquery.io/\n") + return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -1303,6 +1366,9 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://sentimentinvestor.com\n") + return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -1345,6 +1411,9 @@ class KeysController(BaseController): dest="passphrase", help="Passphrase", ) + if not other_args: + console.print("For your API Key, visit: https://docs.pro.coinbase.com/\n") + return ns_parser = parse_known_args_and_warn(parser, other_args) if ns_parser: os.environ["GT_API_COINBASE_KEY"] = ns_parser.key @@ -1381,6 +1450,9 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print("For your API Key, visit: https://docs.whale-alert.io/\n") + return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -1407,6 +1479,11 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print( + "For your API Key, visit: https://docs.glassnode.com/basic-api/api-key#how-to-get-an-api-key/\n" + ) + return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -1433,6 +1510,11 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print( + "For your API Key, visit: https://coinglass.github.io/API-Reference/#api-key\n" + ) + return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -1459,6 +1541,11 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print( + "For your API Key, visit: https://cryptopanic.com/developers/api/\n" + ) + return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -1485,6 +1572,11 @@ class KeysController(BaseController): dest="key", help="key", ) + if not other_args: + console.print( + "For your API Key, visit: https://github.com/EverexIO/Ethplorer/wiki/Ethplorer-API\n" + ) + return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-k") ns_parser = parse_known_args_and_warn(parser, other_args) @@ -1517,7 +1609,9 @@ class KeysController(BaseController): dest="token", help="Token", ) - + if not other_args: + console.print("For your API Key, visit: https://www.smartstake.io\n") + return ns_parser = parse_known_args_and_warn(parser, other_args) if ns_parser: @@ -1530,11 +1624,3 @@ class KeysController(BaseController): cfg.API_SMARTSTAKE_KEY = ns_parser.key self.check_smartstake_key(show_output=True) - - ns_parser = parse_known_args_and_warn(parser, other_args) - if ns_parser: - os.environ["GT_API_ETHPLORER_KEY"] = ns_parser.key - dotenv.set_key(self.env_file, "GT_API_ETHPLORER_KEY", ns_parser.key) - cfg.API_ETHPLORER_KEY = ns_parser.key - - self.check_ethplorer_key(show_output=True)