publish eve_rock_watcher.py

This commit is contained in:
brockdarnold 2026-06-15 03:48:32 +00:00
parent f73dec2c37
commit c966aafef7

View file

@ -241,6 +241,18 @@ def read_rows(cp, region, mode):
return parse_survey(text)
def _fmt_dur(secs):
"""Human time-left, e.g. '1h 04m', '7m 20s', '45s'."""
secs = int(max(0, secs))
h, rem = divmod(secs, 3600)
m, s = divmod(rem, 60)
if h:
return f"{h}h {m:02d}m"
if m:
return f"{m}m {s:02d}s"
return f"{s}s"
def main():
cp = w.load_config()
if "--snip" in sys.argv:
@ -319,7 +331,7 @@ def main():
others = [(o, u) for (k, o, u) in keyed if k != key]
nxt = max(others, key=lambda x: x[1]) if others else None
empty_at = int(now + tleft)
msg = f"{ore.title()} rock empties <t:{empty_at}:R> ({units:,} u left)."
msg = f"{ore.title()} rock empties in ~{_fmt_dur(tleft)} (<t:{empty_at}:R>) — {units:,} u left."
if nxt:
msg += f" Switch to {nxt[0].title()} ({nxt[1]:,} u)."
w.notify(cp, "Switch rocks", msg, priority="high", tags="pick,gem")
@ -330,7 +342,7 @@ def main():
empty_at = int(now + tleft)
others = [(o, u) for (k, o, u) in keyed if k != key]
nxt = max(others, key=lambda x: x[1]) if others else None
line = f"🪨 {ore.title()} {units:,} u · empties <t:{empty_at}:R>"
line = f"🪨 {ore.title()} {units:,} u · ~{_fmt_dur(tleft)} left (empties <t:{empty_at}:R>)"
if nxt:
line += f" · next: {nxt[0].title()} ({nxt[1]:,} u)"
w._discord_live(cp, "rock", f"⛏️ {socket.gethostname()} current rock", line)