# -*- coding: utf-8 -*- """Lokaler NeuronWriter-Score, identischer Pruefkoerper wie WF2 (Kurzantwort + Inhalt + FAQ). Aufruf: python3 build/nw_score.py artikel/artikel-SLUG.json [...]""" import json, os, sys, urllib.request def env(p='.env'): d = {} for z in open(p, encoding='utf-8'): z = z.strip() if z and not z.startswith('#') and '=' in z: k, v = z.split('=', 1); d[k] = v.strip().strip('"') return d E = env() for pfad in sys.argv[1:]: a = json.load(open(pfad, encoding='utf-8')) faq = '\n'.join(f"

{f.get('frage','')}

{f.get('antwort','')}

" for f in a.get('faq') or []) html = '\n'.join([f"

{a['kurzantwort']}

" if a.get('kurzantwort') else '', a['content_html'], f"

{a.get('faq_ueberschrift') or 'Häufige Fragen'}

\n{faq}" if faq else '']) body = json.dumps({'query': a['query_id'], 'html': html, 'title': a.get('seo_titel') or a['titel'], 'description': a.get('seo_beschreibung', '')}).encode() r = urllib.request.Request('https://app.neuronwriter.com/neuron-api/0.5/writer/evaluate-content', data=body, headers={'X-API-KEY': E['NEURONWRITER_API_KEY'], 'Content-Type': 'application/json'}) print(a['slug'], json.load(urllib.request.urlopen(r, timeout=90)).get('content_score'))