20 KiB
Design Notes — BNetzA Amateurfunk Question Catalog Downloader
Status: design only, no code yet. This document captures the source-discovery work and the proposed shape of the tool. Everything below was verified against the live BNetzA site in May 2026.
1. Source of the latest questions
The Bundesnetzagentur (BNetzA) is the authoritative publisher. They provide the exam catalog in two parallel formats from the same landing page:
- PDF — human-readable, ~5 MB.
- ZIP — machine-readable, ~3 MB, contains JSON + SVG figures. This is the format we use.
Landing page
- Short URL:
https://www.bnetza.de/amateurfunk-fragenkatalog- HTTP 301 →
SharedDocs/Downloads/.../Fragenkatalog/KurzURLFragenkatalog.html - The short URL points at an HTML page, not at the ZIP itself. We do not use it for fetching; it is useful only as a citation/attribution target.
- HTTP 301 →
Direct download URLs (verified 2026-05-20)
- ZIP (what we fetch):
https://www.bundesnetzagentur.de/SharedDocs/Downloads/DE/Sachgebiete/Telekommunikation/Unternehmen_Institutionen/Frequenzen/Amateurfunk/Fragenkatalog/PruefungsfragenZIP.zip?__blob=publicationFile- HTTP 200,
Content-Type: application/zip,Accept-Ranges: bytes, serves a freshLast-Modifiedheader. Suitable for conditional fetch and idempotency checks.
- HTTP 200,
- PDF (not used by this tool):
https://www.bundesnetzagentur.de/SharedDocs/Downloads/DE/Sachgebiete/Telekommunikation/Unternehmen_Institutionen/Frequenzen/Amateurfunk/Fragenkatalog/Pruefungsfragen.pdf?__blob=publicationFile
The ?__blob=publicationFile query string is required — without it the
CMS serves an HTML wrapper, not the binary.
License
DL-DE→BY-2.0 (Datenlizenz Deutschland – Namensnennung – Version 2.0,
see www.govdata.de/dl-de/by-2-0). Commercial and non-commercial reuse
is permitted with attribution. The exact attribution string required is
spelled out in the ZIP's README.txt; we copy it verbatim into any
redistribution and into our manifest.json.
Edition tracking
BNetzA does not version the URL. The same PruefungsfragenZIP.zip
path is updated in place when a new edition is published. To detect a
new edition we rely on:
- The HTTP
Last-Modifiedresponse header. - The sha256 of the downloaded ZIP.
- The
metadatablock inside the JSON (edition,issued_on,valid_from).
Current edition observed: 3. Auflage, März 2024 (issued 2024-03-20,
valid from 2024-06-24).
2. ZIP contents (verified by extracting the live file)
fragenkatalog3b.json — single JSON file, full question tree (~1.3 MB)
README.txt — license + schema documentation
svgs/ — 700+ figures (mostly SVG, a few PNG fallbacks)
AB108_q.svg
AB404_a.svg
AB404_b.svg
...
NG302_q.png — a couple of questions ship a PNG alongside
NG302_q.svg the SVG for display-problem fallbacks
Total: 706 entries, 701 of them files. ~1750 questions across classes N, E, A (counts observed: N=571, E=463, A=716).
The JSON filename encodes the edition: fragenkatalog3b.json =
3rd edition, revision b. A future edition will rename this file
(fragenkatalog4a.json, etc.), so the loader must discover it from
the archive (glob fragenkatalog*.json), not hard-code the name.
README.txt highlights
- Confirms the two-part structure: JSON for catalog/questions, SVG for images.
- Confirms the JSON schema (see section 3).
- Notes that question text may contain LaTeX for formulas, intended to be rendered by something like KaTeX.
3. JSON schema
Top-level object:
{
"metadata": {
"edition": "3. Auflage, März 2024",
"issued_on": "2024-03-20",
"valid_from": "2024-06-24",
"license": "DL-DE->BY-2.0"
},
"sections": [ /* recursive section nodes */ ]
}
Each section node is either an inner node (contains nested
sections) or a leaf (contains a questions list):
// inner
{ "title": "Prüfungsfragen im Prüfungsteil: Technische Kenntnisse",
"sections": [ ... ] }
// leaf
{ "title": "Allgemeine mathematische Grundkenntnisse und Größen",
"questions": [ /* question objects */ ] }
Question object (fields per the upstream README):
| field | meaning |
|---|---|
number |
Catalog id, e.g. NA103, AB404. Also the SVG basename. |
class |
License class: "1" = N, "2" = E, "3" = A. |
question |
Question text. May contain LaTeX. |
answer_a |
The correct answer. Always A. |
answer_b |
Distractor. |
answer_c |
Distractor. |
answer_d |
Distractor. |
picture_question |
Optional. Figure shown with the question stem. |
picture_a.._d |
Optional. Per-choice figures. |
The picture_* fields, when present, contain a filename (e.g.
AB404_q.svg) that resolves into svgs/. Convention observed in the
archive: <number>_q.svg for the question figure, <number>_a.svg ..
<number>_d.svg for per-answer figures. A small number of entries also
ship a .png next to the .svg.
Important consumer-side conventions
- Answer A is always correct. Anything that presents the questions to a learner must shuffle A/B/C/D before display, otherwise the exercise is trivial.
- LaTeX in the question text and answers is unescaped — consumers render it (e.g. KaTeX/MathJax). The downloader does not transform it.
- Classes are stored as string digits, not letter codes — map
"1"→N,"2"→E,"3"→Afor display.
Sample question (from fragenkatalog3b.json):
{
"number": "NA103",
"class": "1",
"question": "Laut Datenblatt wiegen 100 m eines bestimmten Drahtes 210 g. Ein vorliegendes Drahtstück desselben Materials wiegt 55 g. Wie lang ist das Drahtstück in etwa?",
"answer_a": "26,2 m",
"answer_b": "382 m",
"answer_c": "115 m",
"answer_d": "38,2 m"
}
Exam structure — how the catalog splits into exam parts and classes
The catalog already encodes two orthogonal axes. The downloader does not slice the data on disk, but any consumer needs to understand both or they will compute the wrong candidate study pool.
Axis 1 — Exam part (Prüfungsteil). The top-level sections[]
array has exactly three entries, one per exam part:
Top-level title |
Question count | ID prefix |
|---|---|---|
Prüfungsfragen im Prüfungsteil: Technische Kenntnisse |
1374 | N*/E*/A* |
Prüfungsfragen im Prüfungsteil: Betriebliche Kenntnisse |
172 | B* |
Prüfungsfragen im Prüfungsteil: Kenntnisse von Vorschriften |
204 | V* |
Consumers can split on the section title (canonical) or on the
question number first letter (shorthand). The first-letter mapping
is: A/E/N → Technische; B → Betriebliche; V → Vorschriften.
Inside Technische, the first letter additionally mirrors the license
class (see Axis 2).
Axis 2 — License class (class field on each question).
Values are "1"=N, "2"=E, "3"=A. Class distribution per exam
part (counts verified against the live catalog, 3rd edition):
| Exam part | class 1 (N) | class 2 (E) | class 3 (A) |
|---|---|---|---|
| Technische | 195 | 463 | 716 |
| Betriebliche | 172 | 0 | 0 |
| Vorschriften | 204 | 0 | 0 |
Two things a consumer must know:
- Operational + Regulations are class-1-only in the data, but
apply to every candidate. BNetzA treats these as a shared
foundation. Do not filter them by
class. - In Technische, the
classfield is a floor, not an equality marker. German amateur-radio exam knowledge is cumulative: a class-E candidate is expected to know everything at class N and E; a class-A candidate knows class N + E + A. Treatingclassas equality underreports the E and A study pools.
The candidate study pools work out as:
- N: 195 (Tech class 1) + 172 (Betr) + 204 (Vor) = 571
- E: (195 + 463) Tech + 172 + 204 = 1034
- A: (195 + 463 + 716) Tech + 172 + 204 = 1750
The 1750 total exactly matches the full catalog, which confirms the floor interpretation: an A candidate's pool is the entire catalog.
Downloader scope. v1 does not split data on disk — the JSON tree carries both axes already and consumers slice it themselves. This subsection exists so that future consumers (study app, flashcards, diff tool) implement the slicing correctly without re-deriving it from the data.
4. Tool design (v1)
Goal
Given no arguments, fetch the current BNetzA ZIP, extract it into a clean per-edition directory, and write a manifest. Re-running is a no-op when the upstream file has not changed.
CLI shape
amateurfunk-fetch [--out DIR] [--force] [--keep-zip]
--out DIR— output root (default./data). Each edition lands inDIR/<edition-slug>/, e.g.data/2024-03-20-3-auflage/.--force— re-download and re-extract even if the existing manifest matches.--keep-zip— keep the raw ZIP alongside the extracted tree (for archival). Default deletes it after successful extraction.
Exit codes: 0 success (extracted or up-to-date), 1 network /
validation error, 2 invalid local state (e.g. a partial previous run
the tool can't reconcile without --force).
Steps
- HEAD the ZIP URL to read
Last-Modified(andContent-Lengthfor a basic sanity range). IfDIR/manifest-latest.jsonexists and itshttp_last_modifiedequals the current server value AND the targetDIR/<slug>/manifest.jsonit points at is present and parseable, exit 0 unchanged. The manifest — not the raw ZIP — is the trusted record after a successful validated extraction; the ZIP sha256 stays in the manifest as provenance, not as something we re-verify on every run. (We delete the ZIP by default; there would be nothing to re-verify against.) - GET the ZIP to a temp file in
DIR/.tmp/. Stream to disk, compute sha256 on the fly. Enforce a compressed max size (e.g. 50 MB) and, after open, a total uncompressed max size (e.g. 200 MB) as a guardrail against zip-bomb-style upstream regressions. - Validate, failing closed on structural problems:
zipfile.is_zipfile()is true.- All ZIP paths are relative and normalized: reject any entry
whose name is absolute, contains a
..segment, or whoseos.path.normpath-result differs in a way that escapes the extraction root — defends against zip-slip. - No symlink entries. ZIPs created on Unix encode symlinks in
the upper 16 bits of
ZipInfo.external_attr(the POSIX mode field). Reject any entry where(zi.external_attr >> 16) & 0o170000 == 0o120000(S_IFLNK), in addition to the path checks above. - Sum of uncompressed sizes is below the configured cap.
- Archive contains exactly one root-level
fragenkatalog*.json. - Archive contains more than 100 file entries whose normalized
path starts with
svgs/. We do not require a standalonesvgs/directory record — many ZIP producers omit directory entries and only emit file entries likesvgs/AB108_q.svg. - The JSON parses and has top-level keys
metadataandsections. metadatacarries the required keysedition,issued_on,valid_from,license. Extra keys are tolerated.- Every section node has either nested
sectionsor aquestionslist (not both, not neither). - Every question has
number,class,question,answer_a,answer_b,answer_c,answer_d. - For every
picture_*reference in a question, the named file exists undersvgs/in the archive. Soft check: missing references do not fail the extraction. They are collected into the manifest asmissing_picturesso consumers can decide locally. Rationale: a single upstream typo should not brick the downloader for every consumer until BNetzA ships a fix.
- Derive edition slug from
metadata.issued_onplus an edition ordinal parsed frommetadata.edition, e.g."3. Auflage, März 2024"+2024-03-20→2024-03-20-3-auflage. The ordinal is taken from the leading\d+in the edition string; if absent, fall back tounknown-auflage. Sortable, filesystem- safe, and independent of German month-name parsing. The full upstreammetadata.editionis preserved verbatim inmanifest.json. - Extract into
DIR/<slug>.tmp/. Replacement semantics:- If
DIR/<slug>/manifest.jsonalready exists and its recordedzip_sha256matches the freshly downloaded ZIP, skip extraction, updatemanifest-latest.jsonif needed, and exit 0. - If
DIR/<slug>/exists but does not match and--forceis not set, exit 2 with a clear message naming the offending directory. - With
--force, after extraction completes intoDIR/<slug>.tmp/, rename the existingDIR/<slug>/toDIR/<slug>.bak/, renameDIR/<slug>.tmp/into place, then removeDIR/<slug>.bak/. A crash between the two renames leaves a recoverable.bakdirectory. .bakcollision policy: ifDIR/<slug>.bak/already exists before the forced replacement starts, exit 2 with a clear error naming the stale.bak/path. A leftover.bak/is evidence that a previous run crashed mid-rename; deciding whether to keep or delete it is the operator's call, not ours. The same applies to a staleDIR/<slug>.tmp/: refuse to overwrite, surface the path. Both checks happen before any rename — no destructive action without a clean predecessor state. Always copy the upstreamREADME.txtverbatim into the extracted tree. The manifest also records the attribution string for convenience, but the file is the source of truth — lossless preservation beats parser-derived fields.
- If
- Write
DIR/<slug>/manifest.jsonwith:source_urlfetched_at(ISO 8601 UTC)http_last_modified(verbatim from the server)zip_sha256zip_sizejson_filename(the actualfragenkatalog*.jsonwe found)- the full upstream
metadatablock - the verbatim attribution string from
README.txt missing_pictures(array of{question_number, field, file}, empty when the archive is clean)
- Atomically update
DIR/manifest-latest.jsonto point at the current slug. Precise sequence:- Write the new content to a sibling
manifest-latest.json.tmpin the same directory as the target. os.fsync(tmp_fd)to flush the tmp file's contents to disk.os.replace(tmp_path, final_path)to atomically swap.- On POSIX, open the containing directory and
os.fsyncits file descriptor so the rename itself is durable. Wrap in atry/except OSErrorand ignore on platforms where directory fsync is not supported (e.g. Windows) — the swap is still atomic, only its on-disk persistence guarantee differs. A symlink atmanifest-latestwould be nicer on POSIX but a small pointer file is portable.
- Write the new content to a sibling
- Clean up the temp ZIP (unless
--keep-zip).
Idempotency and safety
- Never extract directly into the final directory — always into a
sibling
*.tmpthat is renamed on success. A crash mid-extract leaves the previous good edition untouched. - Network calls go through
urllib.requestwith a sane User-Agent (amateurfunk-fetch/<version> (+contact)) and a timeout. Single retry on transient errors (no exponential-backoff library needed for a once-a-quarter download). - No telemetry. No mutation outside
--out.
Testing focus
The most valuable tests are behavioral, not network-bound. The real BNetzA fetch stays as an opt-in integration test (skipped by default); everything else runs against fixture ZIPs.
- Slug generation from sample
metadata(covers normal, missing ordinal, unusual edition strings). - ZIP path rejection: absolute paths,
..segments, symlinks. - Uncompressed-size cap triggers cleanly.
- Validation failures: missing JSON, multiple
fragenkatalog*.json, missingsvgs/, malformed JSON, missing required top-level keys, missing required metadata/question keys, malformed section nodes. missing_picturesis populated but extraction still succeeds when apicture_*reference doesn't resolve (soft check).- Manifest is well-formed and contains the upstream attribution and
metadatablock verbatim. Last-Modifiedround-trip: after a successful extraction, a rerun with the sameLast-Modifiedheader on the HEAD response skips the GET entirely. This is the actual contract idempotency hangs on now that the ZIP is deleted by default.--forcepath: existing non-matchingDIR/<slug>/is replaced via the temp/bak rename dance, and a simulated crash between the two renames leaves a recoverable.bak/.- Atomic write of
manifest-latest.json: a write that fails partway does not corrupt the existing pointer file.
What we deliberately do NOT do in v1
- No PDF mirroring.
- No question rendering (LaTeX, SVG).
- No splitting by class / chapter on disk — the JSON tree already carries that structure and consumers can slice it themselves.
- No diffing between editions. Useful, but a separate tool that reads two manifest dirs.
- No mirror to S3 / a release artifact. Out of scope unless asked.
5. Resolved during review
These were open in the first draft and have been settled:
- Edition slug format — resolved: derive from
issued_on+ numeric edition ordinal, e.g.2024-03-20-3-auflage. Avoids parsing German month names; preserves day-precision; sortable. manifest-latest.jsonlocation — atDIR/root (one stable pointer for consumers); per-editionmanifest.jsonis the immutable record.- Idempotency without a retained ZIP — resolved: the manifest is
the trusted record after extraction.
Last-Modifiedmatch is sufficient to skip the download;zip_sha256is recorded for provenance only. - README.txt preservation — copy verbatim into the extracted tree alongside any derived attribution field in the manifest.
- Missing picture references — soft-validate (record in
missing_pictures, do not fail). Rationale: avoid bricking the tool on an upstream typo.
6. Open questions
These do not block writing v1:
- PNG fallbacks — the archive ships PNGs for ~a handful of figures alongside the SVGs. v1 just extracts everything as-is. A future renderer can prefer SVG and fall back to PNG transparently.
- Schema drift safety — if a future edition adds or renames fields, the validator should warn but not fail. v1 fails closed on missing required top-level/metadata/question keys but tolerates extra keys. We can soften this further if BNetzA evolves the format.
- Packaging — v1 stays a single-file script with
argparse(amateurfunk_fetch.py). Considered and declined: apyproject.tomlpackage with a console-script entry point. For a tool that runs at most quarterly, the packaging ceremony does not pay for itself. Revisit if the scope grows (e.g. importable from another project, distributed on PyPI).