From 387eaf4df57e2c786d5f9d7f593534ad741a5aeb Mon Sep 17 00:00:00 2001 From: Nixevol Date: Thu, 19 Nov 2026 11:24:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=93=E5=8D=A1=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E6=98=BE=E7=A4=BA=EF=BC=8C=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E6=88=AA=E6=96=AD=E7=AC=AC2=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/punchlog/cli.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/punchlog/cli.py b/src/punchlog/cli.py index ac78e22..d31c0c5 100644 --- a/src/punchlog/cli.py +++ b/src/punchlog/cli.py @@ -41,17 +41,27 @@ def _memo_oneline(rec: dict) -> str: return " / ".join(x.strip() for x in (rec.get("memo") or "").replace("\r", "\n").split("\n") if x.strip()) +def _day_memo(records: list) -> tuple[str, str]: + """Use the longest memo of the day; morning and evening punches usually repeat it.""" + best_site, best_memo = "", "" + for rec in records: + memo = _memo_oneline(rec) + if len(memo) >= len(best_memo): + best_memo = memo + best_site = (rec.get("siteName") or "").strip() + return best_site, best_memo + + def print_table(summaries) -> None: - print(f"{'日期':<12}{'次数':>4} {'补卡':<4} {'最早':<9}{'最晚':<9}{'时长h':>6} {'状态':<18}站点 / 打卡内容") + print(f"{'日期':<12}{'次数':>4} {'补卡':<4} {'最早':<9}{'最晚':<9}{'时长h':>6} {'状态':<18}站点") print("-" * 114) for s in summaries: - rec = s.records[-1] if s.records else {} - site = (rec.get("siteName") or "").strip() - memo = _memo_oneline(rec) - extra = (site[:16] + "… " if site else "") + memo + site, memo = _day_memo(s.records) supp = "含补" if s.has_supplement else " " print(f"{s.day.isoformat():<12}{s.count:>4} {supp:<4} {_fmt_t(s.first):<9}{_fmt_t(s.last):<9}" - f"{s.hours:>6.1f} {s.status:<18}{extra[:60]}") + f"{s.hours:>6.1f} {s.status:<18}{site}") + if memo: + print(f" {memo}") def export_csv(rows: list[dict], path: str) -> None: