GWÖ-Antragsprüfer: Automatische Gemeinwohl-Bilanzierung von Parlamentsanträgen nach der GWÖ-Matrix 2.0
Extends generate_pdf_report() with a best-effort second stage that
appends the original Antrag PDF to the freshly rendered GWÖ-Report so
the analysis and its source document live in the same file.
Pipeline
1. WeasyPrint renders the report PDF as before.
2. _append_original_antrag() then:
- Skips silently if assessment.link is empty or non-HTTP (manual
uploads / pasted text leave nothing to fetch).
- Downloads the original PDF via httpx (30s timeout, follow redirects,
custom user agent).
- Validates the response is actually a PDF (Content-Length not relied
on; the magic bytes %PDF- are checked).
- Adds a single A4 separator page that says "Original-Antrag",
repeats the Drucksachen-ID and title, and either confirms the
append or shows the failure reason (HTTP code, network error,
parse error) plus the source URL.
- Appends the downloaded PDF via PyMuPDF doc.insert_pdf().
- Saves to a sibling .tmp file and atomically replaces the original
(PyMuPDF refuses non-incremental save into the same file).
Edge cases handled
- No link / pasted-text upload → no append, no divider, original report
unchanged.
- Download error / 404 / non-PDF response → divider page with explicit
error message and source URL, report still ships.
- PDF parse error → divider page without appended content, error logged.
- Hard failure during save → fall back to the original WeasyPrint PDF.
Verified live in production container against drucksache 8/6645
(Untrending Frauenhass, BÜNDNIS 90/DIE GRÜNEN LSA):
- Report 4 pages + 1 divider + 3 pages original = 8 pages total
- Divider correctly placed at index 4
- Page 5 starts with "(Ausgegeben am 24.02.2026) … Drucksache 8/6645 …
Antrag — Fraktion BÜNDNIS 90/DIE GRÜNEN — Untrending Frauenhass …"
- Negative test with a synthetic 404 link: 5 pages total, divider at
index 4 with "Original-PDF konnte nicht angehängt werden. Grund: HTTP
404".
Resolves #9.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
||
|---|---|---|
| app | ||
| .dockerignore | ||
| .env.example | ||
| .gitignore | ||
| .tarignore | ||
| docker-compose.yml | ||
| Dockerfile | ||
| LICENSE | ||
| README.md | ||
| requirements.txt | ||
GWÖ-Antragsprüfer
Automatische Gemeinwohl-Bilanzierung von Parlamentsanträgen nach der GWÖ-Matrix 2.0 für Gemeinden
🎯 Was ist das?
Der GWÖ-Antragsprüfer analysiert Anträge aus Landesparlamenten (aktuell NRW) und bewertet sie nach den Kriterien der Gemeinwohl-Ökonomie (GWÖ):
- GWÖ-Score (0-10): Wie gut entspricht der Antrag den GWÖ-Werten?
- Matrix-Zuordnung: Welche Felder der GWÖ-Matrix werden adressiert?
- Programmtreue: Passt der Antrag zu Wahl- und Parteiprogrammen?
- Verbesserungsvorschläge: Konkrete Textänderungen mit GWÖ-Begründung
✨ Features
- 🔍 Landtag-Suche: Direkte Anbindung an OPAL (NRW Parlamentsdokumentation)
- 📊 GWÖ-Matrix-Visualisierung: 5×5-Tabelle mit Bewertungssymbolen
- 🏷️ Tag-Wolke: Filter nach Themen mit Multi-Select
- 🎯 Partei-Filter: Durchschnittswerte pro Fraktion
- 📄 PDF-Export: Professionelle Berichte im GWÖ-Design
- 🔒 Security: CSP, CORS, Rate Limiting
🚀 Schnellstart
Voraussetzungen
- Python 3.12+
- Docker & Docker Compose
- DashScope API-Key (Qwen LLM)
Installation
# Repository klonen
git clone https://github.com/tobiasroedel/gwoe-antragspruefer.git
cd gwoe-antragspruefer
# Environment-Variablen
cp .env.example .env
# DASHSCOPE_API_KEY eintragen
# Mit Docker starten
docker compose up -d
# Oder lokal entwickeln
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload
Die App läuft auf http://localhost:8000
📁 Projektstruktur
webapp/
├── app/
│ ├── main.py # FastAPI-Endpoints
│ ├── analyzer.py # LLM-Analyse-Logik
│ ├── database.py # SQLite-Persistenz
│ ├── models.py # Pydantic-Modelle
│ ├── parlamente.py # Landtag-Adapter (OPAL)
│ ├── report.py # PDF-Generierung
│ ├── config.py # Settings
│ ├── kontext/ # GWÖ-Matrix, Wahlprogramme
│ ├── templates/ # Jinja2-HTML
│ └── static/ # CSS, JS, Assets
├── data/ # SQLite-DBs (Volume)
├── reports/ # Generierte PDFs (Volume)
├── docker-compose.yml
├── Dockerfile
└── requirements.txt
🔧 Konfiguration
Environment-Variablen
| Variable | Beschreibung | Default |
|---|---|---|
DASHSCOPE_API_KEY |
Alibaba DashScope API-Key | (required) |
LLM_MODEL_DEFAULT |
Standard-Modell | qwen-plus-latest |
LLM_MODEL_PREMIUM |
Premium-Modell | qwen-max |
Unterstützte Bundesländer
| Code | Name | Status |
|---|---|---|
| NRW | Nordrhein-Westfalen | ✅ Aktiv |
| BY | Bayern | 🔜 Geplant |
| BW | Baden-Württemberg | 🔜 Geplant |
📊 API-Endpoints
| Methode | Pfad | Beschreibung |
|---|---|---|
| GET | / |
Web-UI |
| GET | /api/assessments |
Alle Bewertungen |
| GET | /api/assessment?drucksache=18/12345 |
Einzelne Bewertung |
| POST | /api/analyze-drucksache |
Neue Analyse starten |
| GET | /api/search?q=Klima |
Interne Suche |
| GET | /api/search-landtag?q=Klima |
Landtag-Suche |
| GET | /api/assessment/pdf?drucksache=18/12345 |
PDF-Download |
🧠 GWÖ-Prompt (v5)
Der Analyse-Prompt basiert auf:
- GWÖ-Matrix 2.0 für Gemeinden (Arbeitsbuch)
- ECOnGOOD Corporate Design Manual 2024
- Wahlprogramme der NRW-Landtagsparteien 2022
Ausgabe-Format:
- GWÖ-Score mit Matrix-Feldern und Symbolen (++/+/○/−/−−)
- Wahlprogramm- und Parteiprogrammtreue
- Verbesserungsvorschläge im Redline-Format (Original → Vorschlag → Begründung)
- Themen-Tags für Kategorisierung
🛠️ Entwicklung
# Tests ausführen
pytest
# Linting
ruff check app/
# Type-Checking
mypy app/
📝 Lizenz
MIT License - siehe LICENSE
🙏 Credits
- Gemeinwohl-Ökonomie - Matrix und Arbeitsbücher
- Alibaba DashScope - Qwen LLM API
- Landtag NRW - OPAL-Dokumentation
Entwickelt von Tobias Rödel · tobiasroedel.de