Initial commit: Discord stock bot with hourly PYPL updates
Functional Discord bot with automated hourly stock price updates during NYSE trading hours. Supports manual queries for any ticker via prefix commands. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
49
config.py
Normal file
49
config.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
class Config:
|
||||
"""Application configuration loaded from environment variables."""
|
||||
|
||||
# Discord configuration
|
||||
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN')
|
||||
CHANNEL_ID = os.getenv('CHANNEL_ID')
|
||||
COMMAND_PREFIX = os.getenv('COMMAND_PREFIX', '!')
|
||||
|
||||
# Stock configuration
|
||||
PRIMARY_TICKER = os.getenv('PRIMARY_TICKER', 'PYPL')
|
||||
STOCK_API_PROVIDER = os.getenv('STOCK_API_PROVIDER', 'finnhub') # 'yahoo' or 'finnhub'
|
||||
FINNHUB_API_KEY = os.getenv('FINNHUB_API_KEY')
|
||||
|
||||
# Scheduling configuration
|
||||
UPDATE_INTERVAL_HOURS = int(os.getenv('UPDATE_INTERVAL_HOURS', '1'))
|
||||
|
||||
@classmethod
|
||||
def validate(cls) -> bool:
|
||||
"""
|
||||
Validate that required configuration values are present.
|
||||
|
||||
Returns:
|
||||
True if configuration is valid, False otherwise
|
||||
"""
|
||||
if not cls.DISCORD_TOKEN:
|
||||
print("ERROR: DISCORD_TOKEN not set in environment")
|
||||
return False
|
||||
|
||||
if not cls.CHANNEL_ID:
|
||||
print("ERROR: CHANNEL_ID not set in environment")
|
||||
return False
|
||||
|
||||
try:
|
||||
int(cls.CHANNEL_ID)
|
||||
except ValueError:
|
||||
print("ERROR: CHANNEL_ID must be a numeric Discord channel ID")
|
||||
return False
|
||||
|
||||
if cls.STOCK_API_PROVIDER == 'finnhub' and not cls.FINNHUB_API_KEY:
|
||||
print("ERROR: FINNHUB_API_KEY not set in environment (required when STOCK_API_PROVIDER=finnhub)")
|
||||
return False
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user