mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 15:06:53 +00:00
Merge branch 'Features' into 'master'
Features to finish version 1 Closes #13 See merge request MisterBiggs/simple-telegram-bot!9
This commit is contained in:
commit
2f49d1e99e
@ -1,5 +1,5 @@
|
||||
secrets = {
|
||||
"TELEGRAM_TOKEN": "TELEGRAM BOT TOKEN HERE",
|
||||
"TELEGRAM_TOKEN": "724630968:AAG3-J26jID34AK_SJg5nJCgr7atiVOZc6A",
|
||||
"TWITTER_CONSUMER_API": "CONSUMER_API",
|
||||
"TWITTER_CONSUMER_SECRET": "CONSUMER_SECRET",
|
||||
"TWITTER_ACCESS_TOKEN": "ACCESS_TOKEN",
|
||||
|
@ -11,6 +11,7 @@ import credentials
|
||||
import tickerInfo
|
||||
|
||||
TOKEN = credentials.secrets["TELEGRAM_TOKEN"]
|
||||
TICKER_REGEX = "[$]([a-zA-Z]{1,4})"
|
||||
|
||||
# Enable logging
|
||||
logging.basicConfig(
|
||||
@ -41,17 +42,15 @@ def news(bot, update):
|
||||
|
||||
try:
|
||||
# regex to find tickers in messages, looks for up to 4 word characters following a dollar sign and captures the 4 word characters
|
||||
tickers = re.findall("[$](\w{1,4})", message)
|
||||
tickers = re.findall(TICKER_REGEX, message)
|
||||
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
## Checks if a ticker was passed in
|
||||
if tickers == []:
|
||||
message = "No Ticker, showing Market News:"
|
||||
news = tickerInfo.stockNews("market")
|
||||
for i in range(3):
|
||||
message = "{}\n\n[{}]({})".format(
|
||||
message, news["title"][i], news["link"][i]
|
||||
)
|
||||
for i in range(len(news["title"])):
|
||||
message = f"{message}\n\n[{news['title'][i]}]({news['link'][i]})"
|
||||
update.message.reply_text(
|
||||
text=message, parse_mode=telegram.ParseMode.MARKDOWN
|
||||
)
|
||||
@ -78,7 +77,7 @@ def news(bot, update):
|
||||
)
|
||||
|
||||
news = tickerInfo.stockNews(ticker)
|
||||
for i in range(3):
|
||||
for i in range(len(news["title"])):
|
||||
message = (
|
||||
f"{message}\n\n[{news['title'][i]}]({news['link'][i]})"
|
||||
)
|
||||
@ -98,10 +97,11 @@ def stockInfo(bot, update):
|
||||
|
||||
try:
|
||||
# regex to find tickers in messages, looks for up to 4 word characters following a dollar sign and captures the 4 word characters
|
||||
tickers = re.findall("[$](\w{1,4})", message)
|
||||
tickers = re.findall(TICKER_REGEX, message)
|
||||
|
||||
tickerData = tickerInfo.tickerQuote(tickers)
|
||||
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
if len(tickers) > 0:
|
||||
tickerData = tickerInfo.tickerQuote(tickers)
|
||||
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
for ticker in tickers:
|
||||
ticker = ticker.upper()
|
||||
@ -131,7 +131,7 @@ def dividend(bot, update):
|
||||
chat_id = update.message.chat_id
|
||||
try:
|
||||
# regex to find tickers in messages, looks for up to 4 word characters following a dollar sign and captures the 4 word characters
|
||||
tickers = re.findall("[$](\w{1,4})", message)
|
||||
tickers = re.findall(TICKER_REGEX, message)
|
||||
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
for ticker in tickers:
|
||||
|
@ -39,12 +39,12 @@ def stockNews(ticker):
|
||||
print("Gather News on " + ticker)
|
||||
|
||||
newsLink = f"https://api.iextrading.com/1.0/stock/{ticker}/news/last/5"
|
||||
|
||||
print(newsLink)
|
||||
with urllib.request.urlopen(newsLink) as url:
|
||||
data = json.loads(url.read().decode())
|
||||
|
||||
news = {"link": [], "title": []}
|
||||
for i in range(3):
|
||||
for i in range(len(data)):
|
||||
news["link"].append(data[i]["url"])
|
||||
news["title"].append(data[i]["headline"])
|
||||
return news
|
||||
|
Loading…
x
Reference in New Issue
Block a user