diff --git a/secrets/sensitive.example.yaml b/secrets/sensitive.example.yaml index 951de74c..7f98f1a1 100644 --- a/secrets/sensitive.example.yaml +++ b/secrets/sensitive.example.yaml @@ -296,8 +296,8 @@ MINIFLUX_ADMIN_PASSWORD: change-me-to-something-long-and-random # Rotation is a new Fever password in step 2, then step 3 again. GLANCE_MINIFLUX_FEVER_KEY: change-me-to-the-md5-of-glance-colon-fever-password -# The TSP L 2060 widget on Sports & Markets. Yahoo has no TSP fund, so Glance -# reads the prices from a Google Sheet through the Sheets API. +# The TSP L 2060 and 529 widgets on Sports & Markets. Neither is on Yahoo, so +# Glance reads the prices from a Google Sheet through the Sheets API. # # GLANCE_TSP_SHEET_ID A sheet of PUBLIC prices only, never the operator's # portfolio. Make a new sheet and put in A1: @@ -308,6 +308,13 @@ GLANCE_MINIFLUX_FEVER_KEY: change-me-to-the-md5-of-glance-colon-fever-password # import once, then Share › General access › # Anyone with the link, Viewer. The id is the part # of its URL between /d/ and /edit. +# The 529 card reads a tab named 529 in the same +# sheet. Add it and put in A1: +# =QUERY(IMPORTRANGE("", +# "'Schwab 529'!A1:A60"), "select Col1 where +# Col1 contains ''", 0) +# which gives the plan's one line of text (name, +# unit value, change, YTD) for that portfolio. # GLANCE_GOOGLE_API_KEY Google Cloud console › APIs & Services: enable the # Google Sheets API, then Credentials › Create # credentials › API key, and under API restrictions diff --git a/stacks/sensitive/README.md b/stacks/sensitive/README.md index 5dff3dc3..a92ce214 100644 --- a/stacks/sensitive/README.md +++ b/stacks/sensitive/README.md @@ -634,8 +634,9 @@ everything: - **Sports & Markets** (`sports.yml`): the teams in `GLANCE_TEAMS`, each with its record, last result and next game, and the table each sits in; NBA, NFL, MLB and NHL scores - from ESPN; the full ticker list with charts; and the TSP L 2060 fund with a - year's sparkline. + from ESPN; the full ticker list with charts; the TSP L 2060 fund with a + year's sparkline; the 401(k) fund's mutual-fund twin, LIZKX, likewise; and + the 529 portfolio's unit value, day and year. - **Homelab** (`homelab.yml`): a headline strip, the Estate panel, what fired in the last 24 hours, uptime badges, hosts, every console by category, the household monitor and Saruman's VMs. @@ -702,6 +703,8 @@ is a file under `pages/`, an `$include` line in `glance.yml` and a mount in `trinity` through the Sheets API with a key restricted to that API. The portfolio sheet itself stays private. `GLANCE_TSP_SHEET_ID` and `GLANCE_GOOGLE_API_KEY` are in SOPS, and the example file has the steps. + The 529 card reads a second tab of the same price sheet, `529`, holding + the plan's own line of text for the one portfolio. - **What is in the files is what anyone running this estate would see:** the consoles and addresses `docs/network.md` already lists, the weather (Bellevue, rounded to a city), Hacker News, diff --git a/stacks/sensitive/glance/pages/sports.yml b/stacks/sensitive/glance/pages/sports.yml index f788bae3..3a89beb6 100644 --- a/stacks/sensitive/glance/pages/sports.yml +++ b/stacks/sensitive/glance/pages/sports.yml @@ -3,8 +3,9 @@ # first, then the tables they sit in; under them, the league scoreboards, one # widget per league sharing the first one's template. The sports are ESPN's # public API, no key. Logos are left out: they would be the browser fetching -# from ESPN's CDN. The TSP fund is not on Yahoo, so it is its own widget, read -# from a Google Sheet. +# from ESPN's CDN. Three funds have cards of their own: the TSP fund and the +# 529 portfolio are not on Yahoo and are read from a Google Sheet, and the +# 401(k) fund, which has no public price, is charted by its mutual-fund twin. - name: Sports & Markets slug: sports width: wide @@ -305,3 +306,109 @@ vector-effect="non-scaling-stroke" points="{{ $pts }}"/> {{ end }} + + # 401(k): the plan holds BlackRock's LifePath Index 2060 as a collective + # trust (Fund M), which has no ticker and no public price. LIZKX is the + # same strategy as a mutual fund, on Yahoo with no key, so the card + # charts that: the daily moves match closely, the price is the twin's + # and not the statement's, and the title says so. Yahoo's chart API + # gives a year of closes oldest first; a day with no close is null and + # skipped. Like TSP, it prices once a day. + - type: custom-api + title: 401(k) · LIZKX twin + cache: 6h + url: https://query1.finance.yahoo.com/v8/finance/chart/LIZKX + headers: + User-Agent: Mozilla/5.0 + parameters: + range: 1y + interval: 1d + template: | + {{ $c := .JSON.Array "chart.result.0.indicators.quote.0.close" }} + {{ $n := len $c }} + {{ if or (ne .Response.StatusCode 200) (lt $n 2) }} +

No prices: Yahoo answered {{ .Response.StatusCode }} with {{ $n }} closes.

+ {{ else }} + {{ $p := .JSON.Float "chart.result.0.meta.regularMarketPrice" }} + {{ $day := .JSON.Float "chart.result.0.meta.regularMarketChangePercent" }} + {{ $ts := .JSON.Array "chart.result.0.timestamp" }} + {{ $at := parseTime "unix" ((index $ts (sub (len $ts) 1)).String "") }} + {{ $y0 := 0.0 }}{{ $min := $p }}{{ $max := $p }} + {{ range $c }} + {{ $v := .Float "" }} + {{ if gt $v 0.0 }} + {{ if eq $y0 0.0 }}{{ $y0 = $v }}{{ end }} + {{ if lt $v $min }}{{ $min = $v }}{{ end }} + {{ if gt $v $max }}{{ $max = $v }}{{ end }} + {{ end }} + {{ end }} + {{ $span := sub $max $min }}{{ if le $span 0.0 }}{{ $span = 1.0 }}{{ end }} + {{ $step := div 300.0 (toFloat (sub $n 1)) }} + {{ $pts := "" }} + {{ range $i, $r := $c }} + {{ $v := $r.Float "" }} + {{ if gt $v 0.0 }} + {{ $x := mul (toFloat $i) $step }} + {{ $y := sub 58.0 (mul (div (sub $v $min) $span) 56.0) }} + {{ $pts = printf "%s %.1f,%.1f" $pts $x $y }} + {{ end }} + {{ end }} + {{ $year := mul (div (sub $p $y0) $y0) 100.0 }} +
+
+
{{ printf "$%.2f" $p }}
+
{{ formatTime "01/02/2006" $at }}
+
+
+
+ {{ printf "%+.2f" $day }}% day
+
+ {{ printf "%+.2f" $year }}% over the year
+
+
+ + + + {{ end }} + + # 529: a plan portfolio, not a fund, so not on Yahoo. The operator's + # sheet already scrapes the plan's daily unit values; a "529" tab of + # the same link-shared price sheet that TSP reads holds the one line + # for this portfolio, as the plan's own text (A1). The portfolio's name + # is read from that text, so it is not in this file. Glance cannot turn + # text into a number, so the figures are shown as written; a leading + # minus picks the colour. The scrape keeps only today, so there is no + # line to draw. + - type: custom-api + title: 529 + cache: 6h + url: https://sheets.googleapis.com/v4/spreadsheets/${GLANCE_TSP_SHEET_ID}/values/%27529%27!A1 + headers: + X-Goog-Api-Key: ${GLANCE_GOOGLE_API_KEY} + template: | + {{ $t := .JSON.String "values.0.0" }} + {{ $unit := findSubmatch `Unit\s+value\s+(\$[0-9.,]+)` $t }} + {{ if or (ne .Response.StatusCode 200) (not $unit) }} +

No unit value: the sheet answered {{ .Response.StatusCode }}.

+ {{ else }} + {{ $name := findSubmatch `Name\s+(.+?)\s+Unit\s+value` $t }} + {{ $dc := findSubmatch `Change\s*\(\$\)\s*(-?\$[0-9.,]+)` $t }} + {{ $dp := findSubmatch `Change\s*\(%\)\s*(-?[0-9.]+%)` $t }} + {{ $asof := findSubmatch `as\s+of\s+([0-9/]+)` $t }} + {{ $ytd := findSubmatch `as\s+of\s+[0-9/]+\s+(-?[0-9.]+%)` $t }} +
+
+
{{ $unit }}
+
{{ $name }}
+
+
+
+ {{ $dc }} ({{ $dp }}) day
+
+ {{ $ytd }} this year
+
as of {{ $asof }}
+
+
+ {{ end }}