1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2025-06-16 15:17:28 +00:00

fixed status command

This commit is contained in:
Anson Biggs 2021-03-27 19:10:51 -07:00
parent 621de911cd
commit f65704b0be
4 changed files with 31 additions and 32 deletions

View File

@ -63,7 +63,7 @@ class IEX_Symbol:
if return_df: if return_df:
return symbols, datetime.now() return symbols, datetime.now()
def iex_status(self) -> str: def status(self) -> str:
"""Checks IEX Status dashboard for any current API issues. """Checks IEX Status dashboard for any current API issues.
Returns Returns
@ -71,9 +71,12 @@ class IEX_Symbol:
str str
Human readable text on status of IEX API Human readable text on status of IEX API
""" """
status = r.get("https://pjmps0c34hp7.statuspage.io/api/v2/status.json").json()[ resp = r.get("https://pjmps0c34hp7.statuspage.io/api/v2/status.json")
"status"
] 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": if status["indicator"] == "none":
return "IEX Cloud is currently not reporting any issues with its API." 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" + " 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]]: def search_symbols(self, search: str) -> List[Tuple[str, str]]:
"""Performs a fuzzy search to find stock symbols closest to a search term. """Performs a fuzzy search to find stock symbols closest to a search term.

9
bot.py
View File

@ -64,7 +64,14 @@ def license(update: Update, context: CallbackContext):
def status(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): def donate(update: Update, context: CallbackContext):

View File

@ -52,7 +52,7 @@ class cg_Crypto:
if return_df: if return_df:
return symbols, datetime.now() return symbols, datetime.now()
def cg_status(self) -> str: def status(self) -> str:
"""Checks CoinGecko /ping endpoint for API issues. """Checks CoinGecko /ping endpoint for API issues.
Returns Returns
@ -63,9 +63,9 @@ class cg_Crypto:
status = r.get("https://api.coingecko.com/api/v3/ping") status = r.get("https://api.coingecko.com/api/v3/ping")
if status.status_code == 200: 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: 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]]: def search_symbols(self, search: str) -> List[Tuple[str, str]]:
"""Performs a fuzzy search to find coin symbols closest to a search term. """Performs a fuzzy search to find coin symbols closest to a search term.

View File

@ -54,13 +54,24 @@ class Router:
print(symbols) print(symbols)
return symbols return symbols
def status(self) -> str: def status(self, bot_resp) -> str:
"""Checks for any issues with APIs. """Checks for any issues with APIs.
Returns Returns
------- -------
str 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]]: def search_symbols(self, search: str) -> List[Tuple[str, str]]: