From f65704b0bebed436ae03a4021eda1bbca947bf86 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Sat, 27 Mar 2021 19:10:51 -0700 Subject: [PATCH] fixed status command --- IEX_Symbol.py | 33 +++++++-------------------------- bot.py | 9 ++++++++- cg_Crypto.py | 6 +++--- symbol_router.py | 15 +++++++++++++-- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/IEX_Symbol.py b/IEX_Symbol.py index 60d6e14..b29c6f3 100644 --- a/IEX_Symbol.py +++ b/IEX_Symbol.py @@ -63,7 +63,7 @@ class IEX_Symbol: if return_df: return symbols, datetime.now() - def iex_status(self) -> str: + def status(self) -> str: """Checks IEX Status dashboard for any current API issues. Returns @@ -71,9 +71,12 @@ class IEX_Symbol: str Human readable text on status of IEX API """ - status = r.get("https://pjmps0c34hp7.statuspage.io/api/v2/status.json").json()[ - "status" - ] + resp = r.get("https://pjmps0c34hp7.statuspage.io/api/v2/status.json") + + if resp.status_code == 200: + status = resp.json()["status"] + else: + return "IEX Cloud did not respond. Please check their status page for more information. https://status.iexapis.com" if status["indicator"] == "none": return "IEX Cloud is currently not reporting any issues with its API." @@ -83,28 +86,6 @@ class IEX_Symbol: + " Please check the status page for more information. https://status.iexapis.com" ) - def message_status(self) -> str: - """Checks to see if the bot has available IEX Credits - - Returns - ------- - str - Human readable text on status of IEX Credits. - """ - usage = r.get( - f"https://cloud.iexapis.com/stable/account/metadata?token={self.IEX_TOKEN}" - ).json() - try: - if ( - usage["messagesUsed"] >= usage["messageLimit"] - 10000 - and not usage["payAsYouGoEnabled"] - ): - return "Bot may be out of IEX Credits." - else: - return "Bot has available IEX Credits." - except KeyError: - return "**IEX API could not be reached.**" - def search_symbols(self, search: str) -> List[Tuple[str, str]]: """Performs a fuzzy search to find stock symbols closest to a search term. diff --git a/bot.py b/bot.py index 6dbd90f..7b89a2a 100644 --- a/bot.py +++ b/bot.py @@ -64,7 +64,14 @@ def license(update: Update, context: CallbackContext): def status(update: Update, context: CallbackContext): - update.message.reply_text(text=s.status(), parse_mode=telegram.ParseMode.MARKDOWN) + bot_resp = datetime.datetime.now(update.message.date.tzinfo) - update.message.date + + update.message.reply_text( + text=s.status( + f"It took {bot_resp.total_seconds()} seconds for the bot to get your message." + ), + parse_mode=telegram.ParseMode.MARKDOWN, + ) def donate(update: Update, context: CallbackContext): diff --git a/cg_Crypto.py b/cg_Crypto.py index fa58662..6323188 100644 --- a/cg_Crypto.py +++ b/cg_Crypto.py @@ -52,7 +52,7 @@ class cg_Crypto: if return_df: return symbols, datetime.now() - def cg_status(self) -> str: + def status(self) -> str: """Checks CoinGecko /ping endpoint for API issues. Returns @@ -63,9 +63,9 @@ class cg_Crypto: status = r.get("https://api.coingecko.com/api/v3/ping") if status.status_code == 200: - return "CoinGecko API responded that it was OK in {status.elapsed.total_seconds()} Seconds." + return f"CoinGecko API responded that it was OK in {status.elapsed.total_seconds()} Seconds." else: - return "CoinGecko API returned an error in {status.elapsed.total_seconds()} Seconds." + return f"CoinGecko API returned an error in {status.elapsed.total_seconds()} Seconds." def search_symbols(self, search: str) -> List[Tuple[str, str]]: """Performs a fuzzy search to find coin symbols closest to a search term. diff --git a/symbol_router.py b/symbol_router.py index e7c5de6..b29136b 100644 --- a/symbol_router.py +++ b/symbol_router.py @@ -54,13 +54,24 @@ class Router: print(symbols) return symbols - def status(self) -> str: + def status(self, bot_resp) -> str: """Checks for any issues with APIs. Returns ------- str - Human readable text on status of IEX API + Human readable text on status of the bot and relevant APIs + """ + + return f""" + Bot Status: + {bot_resp} + + Stock Market Data: + {self.stock.status()} + + Cryptocurrency Data: + {self.crypto.status()} """ def search_symbols(self, search: str) -> List[Tuple[str, str]]: