Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions secrets/sensitive.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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("<portfolio sheet URL>",
# "'Schwab 529'!A1:A60"), "select Col1 where
# Col1 contains '<the portfolio's years>'", 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
Expand Down
7 changes: 5 additions & 2 deletions stacks/sensitive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
111 changes: 109 additions & 2 deletions stacks/sensitive/glance/pages/sports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -305,3 +306,109 @@
vector-effect="non-scaling-stroke" points="{{ $pts }}"/>
</svg>
{{ 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) }}
<p class="color-negative">No prices: Yahoo answered {{ .Response.StatusCode }} with {{ $n }} closes.</p>
{{ 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 }}
<div class="flex justify-between items-end">
<div>
<div class="size-h3 color-highlight">{{ printf "$%.2f" $p }}</div>
<div class="size-h6">{{ formatTime "01/02/2006" $at }}</div>
</div>
<div class="text-right size-h6">
<div class="{{ if lt $day 0.0 }}color-negative{{ else }}color-positive{{ end }}">
{{ printf "%+.2f" $day }}% day</div>
<div class="{{ if lt $year 0.0 }}color-negative{{ else }}color-positive{{ end }}">
{{ printf "%+.2f" $year }}% over the year</div>
</div>
</div>
<svg viewBox="0 0 300 60" preserveAspectRatio="none" class="margin-top-10"
style="width: 100%; height: 60px;">
<polyline fill="none" stroke="var(--color-primary)" stroke-width="1.5"
vector-effect="non-scaling-stroke" points="{{ $pts }}"/>
</svg>
{{ 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) }}
<p class="color-negative">No unit value: the sheet answered {{ .Response.StatusCode }}.</p>
{{ 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 }}
<div class="flex justify-between items-end">
<div>
<div class="size-h3 color-highlight">{{ $unit }}</div>
<div class="size-h6">{{ $name }}</div>
</div>
<div class="text-right size-h6">
<div class="{{ if findMatch `^-` $dp }}color-negative{{ else }}color-positive{{ end }}">
{{ $dc }} ({{ $dp }}) day</div>
<div class="{{ if findMatch `^-` $ytd }}color-negative{{ else }}color-positive{{ end }}">
{{ $ytd }} this year</div>
<div>as of {{ $asof }}</div>
</div>
</div>
{{ end }}