diff --git a/build/luecken.py b/build/luecken.py new file mode 100644 index 0000000..6e7e14c --- /dev/null +++ b/build/luecken.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +"""Zeigt Begriffsluecken eines Artikels gegen den lokalen Brief. Aufruf: python3 build/luecken.py SLUG""" +import json, re, sys +s = sys.argv[1] +a = json.load(open(f'artikel/artikel-{s}.json', encoding='utf-8')) +b = json.load(open(f'build/lokal/briefe/{s}.json', encoding='utf-8')) +t = ' '.join([a.get('kurzantwort',''), a['content_html'], a.get('faq_ueberschrift','')] + [f['frage']+' '+f['antwort'] for f in a['faq']]) +t = re.sub(r'<[^>]+>', ' ', t).lower() +print('Pflicht (ist/min-max):') +print(' ' + ', '.join(f"{x['begriff']} {t.count(x['begriff'].lower())}/{x['min']}-{x['max']}" for x in b['begriffe_pflicht'])) +fehl = [x for x in b['begriffe_erweitert'] if t.count(x['begriff'].lower()) < (x['min'] or 1)] +fehl.sort(key=lambda x: -(x['bei_wettbewerbern_pc'] or 0)) +print(f'Erweitert fehlend {len(fehl)}/{len(b["begriffe_erweitert"])}:') +print(' ' + ', '.join(f"{x['begriff']}({x['bei_wettbewerbern_pc']})" for x in fehl)) diff --git a/build/meta_luecken.py b/build/meta_luecken.py new file mode 100644 index 0000000..29b1025 --- /dev/null +++ b/build/meta_luecken.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +"""Titel-, Description- und H2-Begriffe gegen den Brief. Aufruf: python3 build/meta_luecken.py SLUG""" +import json, re, sys +s = sys.argv[1] +a = json.load(open(f'artikel/artikel-{s}.json', encoding='utf-8')) +z = json.load(open(f'build/lokal/briefe/{s}.json', encoding='utf-8'))['zusatz'] +h2 = ' '.join(re.findall(r'

(.*?)

', a['content_html'])) + ' ' + a.get('faq_ueberschrift', '') +for name, text, liste in [('Titel', a['seo_titel'], z.get('begriffe_titel', [])), + ('Description', a['seo_beschreibung'], z.get('begriffe_description', [])), + ('H2', h2, z.get('begriffe_h2', []))]: + fehlt = [b for b in liste if b.lower() not in text.lower()] + print(f'{name}: {text[:160]}\n fehlt: {", ".join(fehlt)}') diff --git a/build/nw_score.py b/build/nw_score.py new file mode 100644 index 0000000..e1e2cf0 --- /dev/null +++ b/build/nw_score.py @@ -0,0 +1,24 @@ +# -*- 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'))