Description

This commit is contained in:
Ian Gulliver
2026-07-25 08:42:24 -07:00
parent 9d0f570c85
commit 700b53d50c
3 changed files with 20 additions and 6 deletions
+4 -1
View File
@@ -42,6 +42,7 @@
.hero .loc { font-size: 6rem; font-weight: 800; line-height: 1; margin: 6px 0; }
.hero.ok .loc { color: #34d399; }
.hero.warn .loc { color: #fbbf24; font-size: 2.4rem; }
.hero .desc { color: #9ca3af; font-size: .9rem; margin-top: 8px; }
.status { font-size: 1.25rem; font-weight: 650; }
.ok { color: #34d399; } .warn { color: #fbbf24; } .err { color: #f87171; } .muted { color: #9ca3af; }
.rows { margin-top: 10px; display: flex; justify-content: space-between; align-items: baseline; font-size: 1.05rem; }
@@ -100,7 +101,9 @@
let html = '<div class="card hero ' + (hasLoc ? 'ok' : 'warn') + '">' +
'<div class="label">Put it away at</div>' +
'<div class="loc">' + (hasLoc ? escapeHtml(res.location) : 'no location') + '</div></div>';
'<div class="loc">' + (hasLoc ? escapeHtml(res.location) : 'no location') + '</div>' +
(res.description ? '<div class="desc">' + escapeHtml(res.description) + '</div>' : '') +
'</div>';
let status, rows = '';
if (res.previous_weight === undefined) {
+2
View File
@@ -32,6 +32,7 @@ type result struct {
Image string `json:"image"`
SpoolID string `json:"spool_id,omitempty"`
URL string `json:"url,omitempty"`
Description string `json:"description,omitempty"` // brand/material/type/color
Location string `json:"location,omitempty"`
PreviousWeight *weightBreakdown `json:"previous_weight,omitempty"` // as read from spooldb
NewWeight *weightBreakdown `json:"new_weight,omitempty"` // from the measured photo
@@ -202,6 +203,7 @@ func processImg(img image.Image, name string, auth claude.Auth, dryRun bool) res
}
if info != nil {
r.Location = info.Location
r.Description = info.Description
r.PreviousWeight = &weightBreakdown{
Spool: ptr(info.EmptySpoolGrams),
Filament: ptr(info.RemainingGrams),
+14 -5
View File
@@ -191,6 +191,7 @@ func (c *Client) Login(ctx context.Context, email, password string) error {
// SpoolInfo is the current state of a spool, read from its edit dialog.
type SpoolInfo struct {
Location string // location label, e.g. "H" (empty if unset)
Description string // brand/material/type/color, e.g. "Bambu Lab ABS GF - Black (41101)"
TotalGrams float64 // weight including the spool (what the scale reads)
RemainingGrams float64 // remaining filament the site tracks
EmptySpoolGrams float64 // empty-spool weight used to derive remaining
@@ -252,23 +253,31 @@ func (c *Client) SpoolInfo(ctx context.Context, spoolID string) (SpoolInfo, erro
const js = `(() => {
const val = id => { const e = document.getElementById(id); return e ? e.value : ''; };
const ph = id => { const e = document.getElementById(id); return e ? e.placeholder : ''; };
const dialog = document.getElementById('weight_with_spool').closest('[role="dialog"]') || document.body;
// The dialog header reads "Edit Spool" then a descriptor line like
// "Bambu Lab ABS GF - Black (41101)" (brand, material, type, color).
const lines = dialog.innerText.split('\n').map(s => s.trim());
const i = lines.indexOf('Edit Spool');
const desc = i >= 0 ? (lines.slice(i + 1).find(s => s.length) || '') : '';
return JSON.stringify({
location: val('location_label'),
total: val('weight_with_spool'),
remaining: val('remaining_grams'),
empty: val('empty_spool_weight') || ph('empty_spool_weight'),
location: val('location_label'),
total: val('weight_with_spool'),
remaining: val('remaining_grams'),
empty: val('empty_spool_weight') || ph('empty_spool_weight'),
description: desc,
});
})()`
var out string
if err := c.run(ctx, 10*time.Second, chromedp.Evaluate(js, &out)); err != nil {
return SpoolInfo{}, err
}
var raw struct{ Location, Total, Remaining, Empty string }
var raw struct{ Location, Total, Remaining, Empty, Description string }
if err := json.Unmarshal([]byte(out), &raw); err != nil {
return SpoolInfo{}, fmt.Errorf("parse spool fields: %w", err)
}
return SpoolInfo{
Location: strings.TrimSpace(raw.Location),
Description: strings.TrimSpace(raw.Description),
TotalGrams: parseGrams(raw.Total),
RemainingGrams: parseGrams(raw.Remaining),
EmptySpoolGrams: parseGrams(raw.Empty),