mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 15:06:53 +00:00
fixed status command
This commit is contained in:
parent
621de911cd
commit
f65704b0be
@ -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.
|
||||
|
||||
|
9
bot.py
9
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):
|
||||
|
@ -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.
|
||||
|
@ -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]]:
|
||||
|
Loading…
x
Reference in New Issue
Block a user