parlament: a written question's addressed minister is no longer recorded as asking it

The list row's "Personen" names the askers and the minister the question is addressed to. Persons who answered
the linked answer (or, for unanswered questions, any answer in the same period) are now left out of the askers.
(Test in the following commit, tests/test_parsers.py.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
simonandClaude Opus 5.5 committed 2026-11-20 14:35:27 +01:00
1 parent 0c8b38a6b4
commit 5640ed653b
1 file changed
+34 -6
+34 -6
View File
@@ -50,13 +50,35 @@ WITNESS_TITLES = re.compile(r"^(?:(?:Oberstaatsanwalt|Staatsanwalt|Sektionschef(
r"Vizekanzler|Präsident(?:in)?)\s+)+") r"Vizekanzler|Präsident(?:in)?)\s+)+")
ANSWERED_BY = re.compile(r"beantwortet durch (\d+/AB)")
def row_pads(row: dict) -> list[str]:
pads = row.get("Personen") or "[]"
pads = json.loads(pads) if isinstance(pads, str) else pads
return [str(p).strip() for p in pads if str(p).strip()]
def question_answerers(rows: list[dict]) -> dict[str, set[str]]:
"""Answer number ("1479/AB") -> persons who answered it; "*" -> everyone who answered any question in the list
(members of the government, used for questions not answered yet)."""
out: dict[str, set[str]] = {"*": set()}
for row in rows:
if row.get("ITYP") == "AB" and row.get("Nummer"):
pads = set(row_pads(row))
out.setdefault(row["Nummer"], set()).update(pads)
out["*"].update(pads)
return out
@register @register
class ParlamentItems(Adapter): class ParlamentItems(Adapter):
spec = SPEC spec = SPEC
name = "parlament.items" name = "parlament.items"
description = "Votes (faction + roll call), immunity requests, written questions, U-committee hearings" description = "Votes (faction + roll call), immunity requests, written questions, U-committee hearings"
schedule = "45 3 * * *" schedule = "45 3 * * *"
parser_version = 3 # 3: immunity reports finding no political connection, cleaner authority and case number parser_version = 4 # 3: immunity reports finding no political connection, cleaner authority and case number
# 4: a written question's addressed minister is no longer recorded as asking it
def start(self, ctx: RunContext) -> Iterator[Request]: def start(self, ctx: RunContext) -> Iterator[Request]:
for gp in ctx.params.get("periods") or get_settings().parlament_periods: for gp in ctx.params.get("periods") or get_settings().parlament_periods:
@@ -76,7 +98,9 @@ class ParlamentItems(Adapter):
# -- list --------------------------------------------------------------------------- # -- list ---------------------------------------------------------------------------
def parse_items(self, ctx: RunContext, response: Response) -> Iterator[Any]: def parse_items(self, ctx: RunContext, response: Response) -> Iterator[Any]:
for row in list_rows(response.json()): rows = list_rows(response.json())
answerers = question_answerers(rows)
for row in rows:
path, subject, kind = row.get("HIS_URL"), row.get("Betreff") or "", row.get("ITYP") path, subject, kind = row.get("HIS_URL"), row.get("Betreff") or "", row.get("ITYP")
if not path: if not path:
continue continue
@@ -88,15 +112,19 @@ class ParlamentItems(Adapter):
yield detail_request(path, kind="immunity", yield detail_request(path, kind="immunity",
meta={"title": subject, "date": row.get("Datum"), "status": row.get("Status")}) meta={"title": subject, "date": row.get("Datum"), "status": row.get("Status")})
if kind in ("J", "AB"): if kind in ("J", "AB"):
yield from self.question_claims(row, path) yield from self.question_claims(row, path, answerers)
if kind == "KOMM" and HEARING.search(subject): if kind == "KOMM" and HEARING.search(subject):
yield detail_request(path, kind="hearing", meta={"title": subject, "date": row.get("Datum")}) yield detail_request(path, kind="hearing", meta={"title": subject, "date": row.get("Datum")})
def question_claims(self, row: dict, path: str) -> Iterator[Claim]: def question_claims(self, row: dict, path: str, answerers: dict[str, set[str]] | None = None) -> Iterator[Claim]:
pads = row.get("Personen") or "[]" pads = row_pads(row)
pads = json.loads(pads) if isinstance(pads, str) else pads
subject = row.get("Betreff") or "" subject = row.get("Betreff") or ""
is_question = row.get("ITYP") == "J" is_question = row.get("ITYP") == "J"
if is_question and answerers:
# "Personen" of a question also lists the minister it is addressed to: not an asker.
answer = ANSWERED_BY.search(subject)
addressed = answerers.get(answer.group(1), set()) if answer else answerers.get("*", set())
pads = [p for p in pads if str(p).strip() not in addressed]
asked = parse_date(row.get("Datum")) asked = parse_date(row.get("Datum"))
topics = tuple(json.loads(row.get("THEMEN") or "[]")) if isinstance(row.get("THEMEN"), str) else () topics = tuple(json.loads(row.get("THEMEN") or "[]")) if isinstance(row.get("THEMEN"), str) else ()
for pad in pads: for pad in pads: