Bank statement PDFs to CSV, part 10: I added a version check — and what I deliberately did not build

Part 6 ended with a list of things this converter had not proven. One item on that list was auto-update: the installer was verified, but once installed, the program had no way to tell you a newer version existed. Upgrading meant re-running a new installer, and nothing would ever prompt you to do it. This post closes half of that item — a version check — and I want to be exact about which half, because the half I did not build matters more than the half I did.

第 6 部分以一份该转换器尚未验证的功能列表结尾。列表中的一项是自动更新:安装程序虽然经过验证,但程序一旦安装,就无法告知用户是否存在更新版本。升级意味着必须重新运行新的安装程序,且没有任何提示。本文完成了该项功能的一半——版本检查——我希望明确指出是哪一半,因为我未构建的那一半比我已构建的那一半更为重要。

What I built: A small module, update_check.py, using only the Python standard library. It does one GET to the GitHub API for the latest release tag of this repository and compares it with the local version, which is now stamped as 0.1.0. The CLI gained two flags: python bank_statement.py --check-update and python bank_statement.py --version.

我构建的内容:一个仅使用 Python 标准库的小模块 update_check.py。它向 GitHub API 发送一次 GET 请求以获取该仓库的最新发布标签,并将其与当前标记为 0.1.0 的本地版本进行比较。命令行界面增加了两个标志:python bank_statement.py --check-update 和 python bank_statement.py --version。

The check returns one of four statuses, and nothing else. update-available when a newer tag exists. up-to-date when the local version is at or above the latest tag. no-release when the repository has no release published yet — the API answers 404, and that is a fact about the repository, not an error. unavailable when the network fails, the response is malformed, or the tag cannot be parsed as a version. A failure is reported as a one-line status and the command still exits 0, because the check is advisory and must never break a conversion.

检查结果仅返回四种状态之一。当存在更新的标签时返回 update-available;当本地版本等于或高于最新标签时返回 up-to-date;当仓库尚未发布任何版本时返回 no-release(API 返回 404,这是关于仓库的事实,而非错误);当网络故障、响应格式错误或标签无法解析为版本号时返回 unavailable。失败情况会以单行状态报告,且命令仍以 0 退出,因为该检查仅供参考,绝不能中断转换过程。

I ran the real check against the live API. The repository has no release published yet, so the honest output is: no release published yet (you have 0.1.0) — nothing to compare against. That is the correct answer today. The first release has not been tagged, so there is nothing to compare against, and the tool says so instead of inventing a version or failing loudly. Once the first release is tagged, the same command will start comparing for real.

我针对实时 API 运行了实际检查。由于该仓库尚未发布任何版本,因此真实的输出是:no release published yet (you have 0.1.0) — nothing to compare against。这是目前的正确答案。由于第一个版本尚未打标签,因此没有可比较的对象,工具会如实告知,而不是虚构一个版本或报错。一旦第一个版本打上标签,同一命令将开始进行实际比较。

The tests are eleven new cases, all with the network faked — a newer tag, the same tag, an older tag, a tag without the v prefix, a 404, a 500, a network error, a non-numeric tag, a missing tag, malformed JSON, and a CLI run that checks and exits 0. The full suite is 22 passed locally, and the CI runs for this commit are green on all three workflows.

测试包含十一个新案例,全部模拟了网络环境:更新的标签、相同的标签、旧标签、不带 v 前缀的标签、404 错误、500 错误、网络错误、非数字标签、缺失标签、格式错误的 JSON,以及一次检查并以 0 退出的 CLI 运行。完整测试套件在本地通过了 22 项,且该提交在所有三个工作流上的 CI 运行均显示通过。

What I deliberately did not build: No download. No install. No check at startup, and no check on every conversion — the converter stays offline by default, and this is the single exception, only when you ask for it. No telemetry of any kind: the request is a plain GET with no account, no file names, nothing about your statements. And no graphical button yet — the check is command-line only for now; the GUI entry is a separate, later piece of work.

我刻意没有构建的功能:没有下载,没有安装。启动时不检查,每次转换时也不检查——转换器默认保持离线状态,这是唯一的例外,仅在你主动要求时才会检查。没有任何形式的遥测:请求只是一个简单的 GET,不包含账户信息、文件名或任何关于你账单的内容。目前也没有图形化按钮——检查功能仅限于命令行;GUI 入口是后续单独的工作。

The reason is scope, not laziness. An auto-updater that downloads and replaces a running executable is a different class of feature: it needs a safe replace-and-restart path on Windows, a rollback story for a bad download, and a signature or checksum story worth trusting. Building a quiet half-measure and calling it auto-update would be worse than saying plainly that it does not exist yet. So the honest statement is: you can now ask whether a newer version exists, in one command, and the answer is one line. Downloading and installing it is still your job, and the README says so in the same section.

原因在于范围,而非懒惰。一个能够下载并替换正在运行的可执行文件的自动更新程序属于不同类别的功能:它需要在 Windows 上有安全的替换和重启路径、针对下载失败的回滚机制,以及值得信赖的签名或校验和方案。构建一个悄无声息的半成品并称之为自动更新,远不如直接说明该功能尚不存在。因此,诚实的说法是:你现在可以通过一个命令询问是否存在更新版本,结果仅为一行。下载和安装仍需由你完成,README 的同一章节也对此进行了说明。

What this does not prove: Auto-update is still missing — this post closes the “does the program know a newer version exists” half, not the “does it install it” half. A real Windows machine install check is still missing. Chinese bank samples are still untested. Those stay on the list from part 6.

这尚未证明的内容:自动更新功能仍然缺失——本文完成了“程序是否知道存在更新版本”这一半,而非“程序是否能安装它”那一半。真正的 Windows 机器安装检查仍然缺失。中国银行的样本仍未测试。这些内容仍保留在第 6 部分的列表中。