Repository navigation
Expand file tree
/
Copy pathtrigger_analysis.sh
More file actions
executable file
·90 lines (80 loc) · 2.68 KB
/
Copy pathtrigger_analysis.sh
File metadata and controls
executable file
·90 lines (80 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
# Usage:
# ./scripts/trigger_analysis.sh TICKER [TICKER ...] [--types TYPE,TYPE]
#
# Examples:
# ./scripts/trigger_analysis.sh IEF AGG VEA
# ./scripts/trigger_analysis.sh AAPL --types fundamental-analysis
# ./scripts/trigger_analysis.sh NVDA TSLA --types fundamental-analysis,technical-analysis
set -euo pipefail
GH="${GH_BIN:-gh}"
REPO="${GH_REPO:-yennanliu/finance_data}"
WORKFLOW="Daily Stock Analysis"
DEFAULT_TYPES="fundamental-analysis,technical-analysis"
DELAY="${TRIGGER_DELAY:-20}" # seconds between workflow dispatches
# ── Parse args ────────────────────────────────────────────────────────────────
TICKERS=()
TYPES="$DEFAULT_TYPES"
while [[ $# -gt 0 ]]; do
case "$1" in
--types)
TYPES="$2"
shift 2
;;
--repo)
REPO="$2"
shift 2
;;
-*)
echo "Unknown flag: $1" >&2
exit 1
;;
*)
TICKERS+=("$1")
shift
;;
esac
done
if [[ ${#TICKERS[@]} -eq 0 ]]; then
echo "Usage: $0 TICKER [TICKER ...] [--types TYPE,TYPE] [--repo owner/repo]"
echo ""
echo "Available analysis types (daily_analysis workflow):"
echo " fundamental-analysis technical-analysis stock-eval"
echo " economics-analysis portfolio-review sector-analysis"
echo " earnings-call-analysis insider-trading institutional-ownership"
echo " report-generator"
echo ""
echo "Note: earnings-call-analysis with transcript URL → use advanced_analysis workflow"
exit 1
fi
# Split TYPES by comma into array
IFS=',' read -ra TYPE_LIST <<< "$TYPES"
# ── Trigger runs ──────────────────────────────────────────────────────────────
TOTAL=$(( ${#TICKERS[@]} * ${#TYPE_LIST[@]} ))
echo "Triggering ${TOTAL} workflow run(s) on [${REPO}]"
echo " Tickers : ${TICKERS[*]}"
echo " Types : ${TYPE_LIST[*]}"
echo ""
SUCCESS=0
FAIL=0
for TICKER in "${TICKERS[@]}"; do
for ATYPE in "${TYPE_LIST[@]}"; do
printf " %-8s %-30s ... " "$TICKER" "$ATYPE"
if URL=$("$GH" workflow run "$WORKFLOW" --repo "$REPO" \
--field ticker="$TICKER" \
--field analysis_type="$ATYPE" 2>&1); then
echo "OK $URL"
(( SUCCESS++ )) || true
else
echo "FAIL: $URL"
(( FAIL++ )) || true
fi
# stagger dispatches to avoid concurrent API rate limits
if [[ $(( SUCCESS + FAIL )) -lt $TOTAL ]]; then
sleep "$DELAY"
fi
done
done
echo ""
echo "Done: ${SUCCESS} triggered, ${FAIL} failed."
[[ $FAIL -eq 0 ]]