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

fixed environ vars since now theres more than 1

This commit is contained in:
Anson 2019-05-28 05:33:16 -07:00
parent 4da5d9933f
commit da5d071f34
2 changed files with 7 additions and 10 deletions

7
bot.py
View File

@ -3,11 +3,10 @@ import logging
import os import os
import telegram import telegram
from functions import *
from telegram.ext import CommandHandler, Filters, MessageHandler, Updater from telegram.ext import CommandHandler, Filters, MessageHandler, Updater
from functions import * TELEGRAM_TOKEN = os.environ["TELEGRAM"]
TOKEN = os.environ["TELEGRAM"]
TICKER_REGEX = "[$]([a-zA-Z]{1,4})" TICKER_REGEX = "[$]([a-zA-Z]{1,4})"
# Enable logging # Enable logging
@ -76,7 +75,7 @@ def error(bot, update, error):
def main(): def main():
"""Start the bot.""" """Start the bot."""
# Create the EventHandler and pass it your bot's token. # Create the EventHandler and pass it your bot's token.
updater = Updater(TOKEN) updater = Updater(TELEGRAM_TOKEN)
# Get the dispatcher to register handlers # Get the dispatcher to register handlers
dp = updater.dispatcher dp = updater.dispatcher

View File

@ -1,12 +1,11 @@
import json import json
import os
import re import re
import time import time
import urllib.request import urllib.request
from datetime import datetime from datetime import datetime
import cred IEX_TOKEN = os.environ["IEX"]
def getTickers(text: str): def getTickers(text: str):
""" """
Takes a blob of text and returns any stock tickers found. Takes a blob of text and returns any stock tickers found.
@ -24,7 +23,7 @@ def tickerDataReply(tickers: list):
tickerReplies = {} tickerReplies = {}
for ticker in tickers: for ticker in tickers:
IEXURL = ( 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: try:
with urllib.request.urlopen(IEXURL) as url: with urllib.request.urlopen(IEXURL) as url:
@ -52,7 +51,7 @@ def tickerDividend(tickers: list):
messages = {} messages = {}
for ticker in tickers: 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: with urllib.request.urlopen(IEXurl) as url:
data = json.loads(url.read().decode()) data = json.loads(url.read().decode())
if data: if data:
@ -77,4 +76,3 @@ def tickerDividend(tickers: list):
messages[ticker] = f"{ticker} either doesn't exist or pays no dividend." messages[ticker] = f"{ticker} either doesn't exist or pays no dividend."
return messages return messages