summaryrefslogtreecommitdiff
path: root/scripts/run.sh
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2026-10-21 15:28:20 +0800
committerJSDurand <mmemmew@gmail.com>2026-10-21 15:28:20 +0800
commit75dd524fadc022d9e6845f41f19203c3d5a951cd (patch)
treeb08ec82fe4358c5f9ea047794bb1ff888b35d64d /scripts/run.sh
parent5c00355c2ccd94195bdb90e1c1e6f51acbcdd7a5 (diff)
add VPS snapshot pipeline, run.sh, and data-repair fixesHEADmaster
- fetch_tw_daily.sh: --snapshot mode (one file per trading day, merged by symbol), retries, validation of numeric fields - cron_daily.sh (VPS): lock, pruning, e-mail alerts on failure - sync_from_vps.sh (Mac): rsync snapshots and merge into per-stock CSVs - run.sh: pick data files for a symbol, build, analyse, open the page - lib.sh: LC_ALL=C; fetch.sh: small fixes - data.rs: repair rows whose open/close fall outside high/low - template: horizontal hover lines in the RSI and KD panels Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'scripts/run.sh')
-rwxr-xr-xscripts/run.sh53
1 files changed, 53 insertions, 0 deletions
diff --git a/scripts/run.sh b/scripts/run.sh
new file mode 100755
index 0000000..463740b
--- /dev/null
+++ b/scripts/run.sh
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+# Input a number and the script picks the right data and runs the
+# executable to produce the HTML web page, and then opens the page
+# with the default web browser.
+#
+# scripts/run.sh SYMBOL
+#
+# The SYMBOL does not have to contain TW or TWO; the script finds the
+# correct one. If both options exist, do both.
+#
+# Extra options are passed on to the analyser, e.g.
+# scripts/run.sh 2330 --interval week
+#
+# Environment: DATA_DIR (default data/tw), HTML_DIR (default data/html), OPEN_CMD (default `open`
+# on macOS, `xdg-open` elsewhere). The page is written to $HTML_DIR/CODE.TW.html (or .TWO.html).
+set -u
+cd "$(dirname "$0")/.." || exit 1 # project root, so it works from any directory
+data=${DATA_DIR:-data/tw}; htmldir=${HTML_DIR:-data/html}
+
+[ $# -ge 1 ] || { sed -n '2,15p' "$0"; exit 2; }
+sym=$1; shift
+
+# An explicit suffix (2330.TW / 6488.TWO) selects that market only; otherwise try both.
+case $sym in
+ *.[Tt][Ww][Oo]) code=${sym%.*}; candidates=("$data/$code.TWO.csv");;
+ *.[Tt][Ww]) code=${sym%.*}; candidates=("$data/$code.TW.csv");;
+ *) code=$sym; candidates=("$data/$code.TW.csv" "$data/$code.TWO.csv");;
+esac
+
+files=(); for f in "${candidates[@]}"; do [ -s "$f" ] && files+=("$f"); done
+if [ ${#files[@]} -eq 0 ]; then
+ echo "no data for '$sym' in $data (looked for: ${candidates[*]})" >&2
+ echo "download it first, e.g.: scripts/fetch.sh -d $data 2010-01-01 \$(date +%F) $code" >&2
+ exit 1
+fi
+
+cargo build --release -q || { echo "build failed" >&2; exit 1; }
+bin=target/release/stock
+mkdir -p "$htmldir"
+
+pages=()
+for f in "${files[@]}"; do
+ page="$htmldir/$(basename "$f" .csv).html"
+ echo "== $(basename "$f" .csv)"
+ "$bin" "$f" -o "$page" "$@" || { echo "analysis failed for $f" >&2; exit 1; }
+ pages+=("$page")
+done
+
+if [ -n "${OPEN_CMD:-}" ]; then opener=$OPEN_CMD
+elif command -v open >/dev/null; then opener=open
+elif command -v xdg-open >/dev/null; then opener=xdg-open
+else echo "no program to open pages with; open them yourself: ${pages[*]}"; exit 0; fi
+for page in "${pages[@]}"; do $opener "$page"; done