Download scripts/refresh.sh from eagle0504/sec-13f-holdings: direct link, hf CLI and curl.
- Browser
- Download file 3.92 kB
-
https://huggingface.co/datasets/eagle0504/sec-13f-holdings/resolve/main/scripts/refresh.sh
- Command line
-
hf download hf://datasets/eagle0504/sec-13f-holdings/scripts/refresh.sh
-
curl -L -o refresh.sh https://huggingface.co/datasets/eagle0504/sec-13f-holdings/resolve/main/scripts/refresh.sh
3.92 kB
| # One command for the whole quarterly refresh, in the right order. | |
| # | |
| # bash industry-reports/13f/refresh.sh --check # is there anything new? | |
| # bash industry-reports/13f/refresh.sh # fetch + build + verify | |
| # bash industry-reports/13f/refresh.sh --publish # ... + S3 + Hugging Face | |
| # bash industry-reports/13f/refresh.sh --publish --only berkshire-hathaway | |
| # | |
| # 13F filings land 45 days after quarter end, so this is a four-times-a-year job: | |
| # mid-February, mid-May, mid-August, mid-November. | |
| # | |
| # Every step is idempotent. Panels are rebuilt from scratch rather than appended | |
| # to, `aws s3 sync --delete` mirrors rather than accumulates, and the Hugging Face | |
| # upload replaces the files in place. Running this twice produces the same result | |
| # as running it once; there is no way to double-count a quarter by re-running. | |
| # | |
| # After --publish, the site itself still needs its usual manual deploy (see | |
| # README.md) -- this script does not touch Amplify. | |
| set -euo pipefail | |
| HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| cd "$HERE" | |
| ALL_SLUGS=$(python3 -c "import json;print(' '.join(f['slug'] for f in json.load(open('funds.json'))))") | |
| PUBLISH=0 | |
| CHECK=0 | |
| SLUGS="$ALL_SLUGS" | |
| while [ $# -gt 0 ]; do | |
| case "$1" in | |
| --publish) PUBLISH=1; shift ;; | |
| --check) CHECK=1; shift ;; | |
| --only) SLUGS="$2"; shift 2 ;; | |
| *) echo "unknown argument: $1" >&2; exit 2 ;; | |
| esac | |
| done | |
| # ---- --check: ask EDGAR whether any fund has filed since the local panel ---- | |
| if [ "$CHECK" = "1" ]; then | |
| python3 - $SLUGS <<'PY' | |
| import json, pathlib, sys, time, urllib.request | |
| UA = {"User-Agent": "Yiqiao Yin y-yin.io research eagle0504@gmail.com"} | |
| funds = {f["slug"]: f for f in json.loads(pathlib.Path("funds.json").read_text())} | |
| stale = [] | |
| for slug in sys.argv[1:]: | |
| cik = funds[slug]["cik"] | |
| have = None | |
| p = pathlib.Path(f"data/{slug}.json") | |
| if p.exists(): | |
| have = json.loads(p.read_text())["quarters"][-1]["period"] | |
| req = urllib.request.Request( | |
| f"https://data.sec.gov/submissions/CIK{cik}.json", headers=UA) | |
| r = json.load(urllib.request.urlopen(req, timeout=45))["filings"]["recent"] | |
| time.sleep(0.15) | |
| newest = max((r["reportDate"][i] or r["filingDate"][i] | |
| for i in range(len(r["form"])) if r["form"][i].startswith("13F-HR")), | |
| default=None) | |
| flag = "NEW" if newest and (have is None or newest > have) else " -" | |
| if flag == "NEW": | |
| stale.append(slug) | |
| print(f" {flag} {slug:28s} local={have or 'none':10s} edgar={newest or 'none'}") | |
| print(f"\n{len(stale)} fund(s) with a newer filing" + (f": {' '.join(stale)}" if stale else "")) | |
| PY | |
| exit 0 | |
| fi | |
| echo "=== 1/4 fetch panels from SEC EDGAR ===" | |
| for s in $SLUGS; do | |
| echo "--- $s" | |
| python3 fetch_13f.py --slug "$s" # site panel (top_n applies) | |
| python3 fetch_13f.py --slug "$s" --out data-full # complete panel for research | |
| done | |
| echo | |
| echo "=== 2/4 build pages ===" | |
| for s in $SLUGS; do | |
| python3 build_13f_html.py --slug "$s" | |
| done | |
| python3 build_13f_html.py --index $ALL_SLUGS | |
| echo | |
| echo "=== 3/4 verify every page's JavaScript ===" | |
| for s in $SLUGS; do | |
| node verify_page.cjs "$s" | tail -1 | sed "s|^| $s: |" | |
| done | |
| echo | |
| echo "=== 4/4 assemble the deploy bundle ===" | |
| rm -rf site | |
| python3 build_13f_html.py --index $ALL_SLUGS >/dev/null | |
| for s in $ALL_SLUGS; do | |
| mkdir -p "site/$s" | |
| cp "$s/index.html" "site/$s/index.html" | |
| done | |
| python3 -c "import shutil; shutil.make_archive('site','zip','site')" | |
| echo " site.zip ready — deploy to Amplify app d3ei9jkfbke20x (see README.md)" | |
| if [ "$PUBLISH" = "1" ]; then | |
| echo | |
| echo "=== publish: S3 ===" | |
| bash push_to_s3.sh | |
| echo | |
| echo "=== publish: Hugging Face ===" | |
| if [ -z "${HF_TOKEN:-}" ]; then | |
| echo " HF_TOKEN not set — skipping. Export it and run: python3 push_to_hf.py" >&2 | |
| else | |
| python3 push_to_hf.py | |
| fi | |
| fi | |
| echo | |
| echo "done." | |