mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 15:06:53 +00:00
fixed environ vars since now theres more than 1
This commit is contained in:
parent
4da5d9933f
commit
da5d071f34
7
bot.py
7
bot.py
@ -3,11 +3,10 @@ import logging
|
||||
import os
|
||||
|
||||
import telegram
|
||||
from functions import *
|
||||
from telegram.ext import CommandHandler, Filters, MessageHandler, Updater
|
||||
|
||||
from functions import *
|
||||
|
||||
TOKEN = os.environ["TELEGRAM"]
|
||||
TELEGRAM_TOKEN = os.environ["TELEGRAM"]
|
||||
TICKER_REGEX = "[$]([a-zA-Z]{1,4})"
|
||||
|
||||
# Enable logging
|
||||
@ -76,7 +75,7 @@ def error(bot, update, error):
|
||||
def main():
|
||||
"""Start the bot."""
|
||||
# Create the EventHandler and pass it your bot's token.
|
||||
updater = Updater(TOKEN)
|
||||
updater = Updater(TELEGRAM_TOKEN)
|
||||
|
||||
# Get the dispatcher to register handlers
|
||||
dp = updater.dispatcher
|
||||
|
10
functions.py
10
functions.py
@ -1,12 +1,11 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import urllib.request
|
||||
from datetime import datetime
|
||||
|
||||
import cred
|
||||
|
||||
|
||||
IEX_TOKEN = os.environ["IEX"]
|
||||
def getTickers(text: str):
|
||||
"""
|
||||
Takes a blob of text and returns any stock tickers found.
|
||||
@ -24,7 +23,7 @@ def tickerDataReply(tickers: list):
|
||||
tickerReplies = {}
|
||||
for ticker in tickers:
|
||||
IEXURL = (
|
||||
f"https://cloud.iexapis.com/stable/stock/{ticker}/quote?token={cred.secret}"
|
||||
f"https://cloud.iexapis.com/stable/stock/{ticker}/quote?token={IEX_TOKEN}"
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(IEXURL) as url:
|
||||
@ -52,7 +51,7 @@ def tickerDividend(tickers: list):
|
||||
messages = {}
|
||||
|
||||
for ticker in tickers:
|
||||
IEXurl = f"https://cloud.iexapis.com/stable/stock/{ticker}/dividends/next?token={cred.secret}"
|
||||
IEXurl = f"https://cloud.iexapis.com/stable/stock/{ticker}/dividends/next?token={IEX_TOKEN}"
|
||||
with urllib.request.urlopen(IEXurl) as url:
|
||||
data = json.loads(url.read().decode())
|
||||
if data:
|
||||
@ -77,4 +76,3 @@ def tickerDividend(tickers: list):
|
||||
messages[ticker] = f"{ticker} either doesn't exist or pays no dividend."
|
||||
|
||||
return messages
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user