SPB Git

spb/wp39_uqo

Public
1.7 KB · 17 lines shellscript
1#!/bin/bash2# Phase 2a (run ON the FinData storage node M3U96a): read-only Postgres extracts of three tables the API does not expose.3# Documented exception (docs/API_INTEGRATION.md). Outputs go to $WP39_CACHE/external and are hashed into manifests.4set -euo pipefail5OUT="${WP39_CACHE:-$HOME/wp39-cache}/external"; mkdir -p "$OUT"6MAN="$(cd "$(dirname "$0")/.." && pwd)/artifacts/manifests"; mkdir -p "$MAN"7psql -d findata -Atc "\copy (select entity_id, security_id, min(fiscal_period_end) first_q, max(fiscal_period_end) last_q, count(distinct fiscal_period_end) n_q, min(filing_date) first_filing from fundamentals_facts where fiscal_period_type='q' and metric='rev' group by 1,2 order by 1) to '$OUT/entities.csv' csv header"8psql -d findata -Atc "\copy (select entity_id, event_date, eps_estimate, eps_reported, release_time, source_id from earnings_events where event_date <= date '2026-10-30' order by 1,2) to '$OUT/earnings_events.csv' csv header"9psql -d findata -Atc "\copy (select symbol, action_type, ex_date, ratio, amount from corporate_actions order by 1,3) to '$OUT/corporate_actions.csv' csv header" 2>/dev/null || \10psql -d findata -Atc "\copy (select * from corporate_actions order by 1) to '$OUT/corporate_actions_raw.csv' csv header"11for f in entities earnings_events corporate_actions corporate_actions_raw; do12  [ -f "$OUT/$f.csv" ] || continue13  rows=$(($(wc -l < "$OUT/$f.csv") - 1)); sha=$(shasum -a 256 "$OUT/$f.csv" | cut -d' ' -f1)14  printf '{"table":"%s","rows":%d,"sha256":"%s","extracted_at":"%s","source":"findata postgres (read-only copy)","license":"frd-private"}\n' "$f" "$rows" "$sha" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > "$MAN/node_extract_$f.json"15  echo "$f: $rows rows"16done17
Files · main
Menu

Theme