okf-wiki/gates/stubs/fasit_reader.py
Kjell Tore Guttormsen 0fd86a23a3
okf-wiki 1.1.1
First public release, published as one snapshot. What changed between
versions is in CHANGELOG.md.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-14 21:03:20 +01:00

26 lines
905 B
Python

"""Known-positive reader for the file-type gate: answers every query from the frozen pairs file (the fasit itself).
It reads no source file. A GREEN gate with it shows that the pairs, the manifest and the gate's scoring agree;
it says nothing about any real reader.
Usage: python3 gates/stubs/fasit_reader.py {file} {queries} <pairs.json>
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
def main() -> int:
queries = json.loads(Path(sys.argv[2]).read_text(encoding="utf-8"))
key = {p["id"]: p for p in json.loads(Path(sys.argv[3]).read_text(encoding="utf-8"))["pairs"]}
answers = [{"id": q["id"], "found": [{"locator": key[q["id"]]["locator"], "hidden": key[q["id"]]["hidden"]}]}
for q in queries["queries"] if q["id"] in key]
print(json.dumps({"answers": answers}))
return 0
if __name__ == "__main__":
sys.exit(main())