mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-06-16 15:17:28 +00:00
Close #47
This commit is contained in:
parent
15be601a38
commit
a44008234a
61
functions.py
61
functions.py
@ -266,10 +266,26 @@ _Donations can only be made in a chat directly with @simplestockbot_
|
|||||||
"""
|
"""
|
||||||
divMessages = {}
|
divMessages = {}
|
||||||
|
|
||||||
for symbol in symbols:
|
IEXurl = f"https://cloud.iexapis.com/stable/stock/msft/dividends/next?token={self.IEX_TOKEN}"
|
||||||
IEXurl = f"https://cloud.iexapis.com/stable/data-points/{symbol}/NEXTDIVIDENDDATE?token={self.IEX_TOKEN}"
|
response = r.get(IEXurl)
|
||||||
response = r.get(IEXurl)
|
if response.status_code == 200:
|
||||||
if response.status_code == 200:
|
IEXData = response.json()[0]
|
||||||
|
keys = (
|
||||||
|
"amount",
|
||||||
|
"currency",
|
||||||
|
"declaredDate",
|
||||||
|
"exDate",
|
||||||
|
"frequency",
|
||||||
|
"paymentDate",
|
||||||
|
"flag",
|
||||||
|
)
|
||||||
|
|
||||||
|
if set(keys).issubset(IEXData):
|
||||||
|
|
||||||
|
if IEXData["currency"] == "USD":
|
||||||
|
price = f"${IEXData['amount']}"
|
||||||
|
else:
|
||||||
|
price = f"{IEXData['amount']} {IEXData['currency']}"
|
||||||
|
|
||||||
# extract date from json
|
# extract date from json
|
||||||
date = response.json()
|
date = response.json()
|
||||||
@ -277,25 +293,26 @@ _Donations can only be made in a chat directly with @simplestockbot_
|
|||||||
pattern = "%Y-%m-%d"
|
pattern = "%Y-%m-%d"
|
||||||
divDate = datetime.strptime(date, pattern)
|
divDate = datetime.strptime(date, pattern)
|
||||||
|
|
||||||
daysDelta = (divDate - datetime.now()).days
|
declared = datetime.strptime(IEXData["declaredDate"], pattern).strftime(
|
||||||
datePretty = divDate.strftime("%A, %B %w")
|
"%A, %B %w"
|
||||||
if daysDelta < 0:
|
)
|
||||||
divMessages[
|
ex = datetime.strptime(IEXData["exDate"], pattern).strftime("%A, %B %w")
|
||||||
symbol
|
payment = datetime.strptime(IEXData["paymentDate"], pattern).strftime(
|
||||||
] = f"{symbol.upper()} dividend was on {datePretty} and a new date hasn't been announced yet."
|
"%A, %B %w"
|
||||||
elif daysDelta > 0:
|
)
|
||||||
divMessages[
|
|
||||||
symbol
|
|
||||||
] = f"{symbol.upper()} dividend is on {datePretty} which is in {daysDelta} Days."
|
|
||||||
else:
|
|
||||||
divMessages[symbol] = f"{symbol.upper()} is today."
|
|
||||||
|
|
||||||
else:
|
daysDelta = (
|
||||||
divMessages[
|
datetime.strptime(IEXData["paymentDate"], pattern) - datetime.now()
|
||||||
symbol
|
).days
|
||||||
] = f"{symbol} either doesn't exist or pays no dividend."
|
print(self.symbol_list)
|
||||||
|
return (
|
||||||
|
f"The next dividend for ${self.symbol_list[self.symbol_list['symbol']==symbol.upper()]['description'].item()}"
|
||||||
|
+ f" is on {payment} which is in {daysDelta} days."
|
||||||
|
+ f" The dividend is for {price} per share."
|
||||||
|
+ f"\nThe dividend was declared on {declared} and the ex-dividend date is {ex}"
|
||||||
|
)
|
||||||
|
|
||||||
return divMessages
|
return f"{symbol} either doesn't exist or pays no dividend."
|
||||||
|
|
||||||
def news_reply(self, symbols: list) -> dict[str, str]:
|
def news_reply(self, symbols: list) -> dict[str, str]:
|
||||||
"""Gets recent english news on stock symbols.
|
"""Gets recent english news on stock symbols.
|
||||||
@ -307,7 +324,7 @@ _Donations can only be made in a chat directly with @simplestockbot_
|
|||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
dict[str, str]
|
Dict[str, str]
|
||||||
Each symbol passed in is a key with its value being a human readable markdown formatted string of the symbols news.
|
Each symbol passed in is a key with its value being a human readable markdown formatted string of the symbols news.
|
||||||
"""
|
"""
|
||||||
newsMessages = {}
|
newsMessages = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user