Firmenbuch (JustizOnline HVD): register numbers and politicians' company functions

- firmenbuch.search: register number for companies linked to people/parties, only for
  one current register entry with the same name
- firmenbuch.extracts: current extracts; officers/shareholders who are politicians in
  the database (exact birth date + name, new person hint birth_date) become company_role
  claims; nobody else is stored, raw responses are not archived, addresses never read;
  the register's daily change list triggers re-extracts
- enrich.firmenbuch closes roles a newer extract no longer lists
- Request.data (raw body, part of the fingerprint); SOAP faults are not retried
- firmenbuch_number drops leading zeros; migration 0009 adds company_role and aligns
  stored numbers; internal politrack_org ids are no longer stored as identifiers
- company_role in API types, MCP docs, person money tab, connections, labels

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
simonandClaude Opus 5.5 committed 2026-11-19 11:33:01 +01:00
1 parent 68be25a953
commit 10c677ca70
30 files changed
+597 -20

No files matched your search

+6 -2
View File
@@ -50,14 +50,18 @@ class Request:
method: str = "GET"
params: dict[str, Any] | None = None
json: Any = None
headers: dict[str, str] | None = None
data: bytes | None = None # raw request body (e.g. a SOAP envelope); part of the fingerprint
headers: dict[str, str] | None = None # never archived (may carry API keys)
meta: dict[str, Any] = field(default_factory=dict, compare=False, hash=False)
conditional: bool = True # send If-None-Match / If-Modified-Since
skip_unchanged: bool = True # body + parser_version unchanged: follow-ups only
@property
def fingerprint(self) -> str:
raw = json.dumps([self.method, self.url, self.params or {}, self.json], sort_keys=True, default=str)
parts: list[Any] = [self.method, self.url, self.params or {}, self.json]
if self.data is not None:
parts.append(self.data.decode("utf-8", "replace"))
raw = json.dumps(parts, sort_keys=True, default=str)
return hashlib.sha256(raw.encode()).hexdigest()[:32]
def describe(self) -> dict[str, Any]:
+8 -2
View File
@@ -30,6 +30,11 @@ log = logging.getLogger(__name__)
RETRY_STATUS = {429, 500, 502, 503, 504}
def is_soap_fault(resp: httpx.Response) -> bool:
"""A SOAP service answers a bad request with HTTP 500 and a Fault body; retrying can't change the answer."""
return resp.status_code == 500 and b"Fault>" in resp.content[:4000]
class Disallowed(Exception):
"""robots.txt forbids fetching this URL."""
@@ -121,14 +126,15 @@ class Fetcher:
for attempt in range(attempts):
self._throttle(req.url, spec)
try:
resp = self.client.request(req.method, req.url, params=req.params, json=req.json, headers=headers)
resp = self.client.request(req.method, req.url, params=req.params, json=req.json, content=req.data,
headers=headers)
except httpx.TransportError as exc:
if attempt == attempts - 1:
raise
log.warning("transport error %s (%s), retrying", req.url, exc)
time.sleep(min(5 * 2 ** attempt, 120))
continue
if resp.status_code in RETRY_STATUS and attempt < attempts - 1:
if resp.status_code in RETRY_STATUS and attempt < attempts - 1 and not is_soap_fault(resp):
retry_after = resp.headers.get("Retry-After", "")
time.sleep(min(float(retry_after) if retry_after.isdigit() else 5 * 2 ** attempt, 300))
continue
+8 -1
View File
@@ -9,6 +9,8 @@ Hint strategies for persons (documented in docs/data-model.md):
office + on holder of an office title on a date (Council of Ministers minutes)
birth_year exact name and year of birth (candidate lists); add no_name_match so that a name
alone never matches when the year doesn't
birth_date exact date of birth and the same name or a variant of it (company register officers);
with no_name_match, people who are not in the database are never matched or created
"""
from __future__ import annotations
@@ -197,6 +199,11 @@ class Resolver:
(normalize(strip_titles(ref.name)), int(hints["birth_year"])),
).fetchall()
return rows[0]["id"] if len(rows) == 1 else None
if "birth_date" in hints and ref.name:
rows = self.conn.execute("SELECT id, full_name FROM person WHERE birth_date = %s",
(hints["birth_date"],)).fetchall()
hits = {r["id"] for r in rows if variant_of(ref.name, r["full_name"])}
return hits.pop() if len(hits) == 1 else None
return None
def office_holder(self, office: str, on: date | None) -> int | None:
@@ -325,7 +332,7 @@ class Resolver:
def _add_org_ids(self, org_id: int, ref: OrgRef) -> None:
for scheme, value in ref.ids.items():
if value:
if value and scheme != "politrack_org": # internal lookup id, not an external identifier
self.conn.execute(
"INSERT INTO identifier (entity_type, entity_id, scheme, value) VALUES ('organization', %s, %s, %s) "
"ON CONFLICT DO NOTHING",