stock-ai-agent/scripts/stock.sh
2026-02-20 10:02:00 +08:00

42 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 美股分析快捷脚本
#
# 用法:
# ./scripts/stock.sh AAPL
# ./scripts/stock.sh AAPL TSLA
# ./scripts/stock.sh # 分析配置的所有股票(会发送通知)
cd "$(dirname "$0")/.." || exit 1
if [ $# -eq 0 ]; then
# 无参数,分析配置的所有股票
echo "📊 分析配置的所有股票(将发送通知)..."
# 直接从 .env 文件读取股票代码
if [ -f .env ]; then
# 使用 grep 提取 STOCK_SYMBOLS 行,然后提取值
STOCKS=$(grep "^STOCK_SYMBOLS=" .env | cut -d'=' -f2)
if [ -z "$STOCKS" ]; then
echo "❌ 无法从 .env 文件读取股票列表"
exit 1
fi
echo "📋 股票列表: $STOCKS"
# 使用 read array 来正确处理空格分隔的股票代码
# 将逗号分隔转换为空格分隔
STOCKS_SPACE=$(echo "$STOCKS" | tr ',' ' ')
# 直接传递给 test_stock.py不要用 while read 循环)
python3 scripts/test_stock.py $STOCKS_SPACE
else
echo "❌ .env 文件不存在"
exit 1
fi
else
# 分析指定的股票 - 使用引号正确传递参数
echo "📊 分析股票: $*(将发送通知)"
python3 scripts/test_stock.py "$@"
fi