Score-Tools, Artikel nachgeschaerft
This commit is contained in:
14
build/luecken.py
Normal file
14
build/luecken.py
Normal file
@@ -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))
|
||||
12
build/meta_luecken.py
Normal file
12
build/meta_luecken.py
Normal file
@@ -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'<h2>(.*?)</h2>', 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)}')
|
||||
24
build/nw_score.py
Normal file
24
build/nw_score.py
Normal file
@@ -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"<h3>{f.get('frage','')}</h3><p>{f.get('antwort','')}</p>" for f in a.get('faq') or [])
|
||||
html = '\n'.join([f"<p>{a['kurzantwort']}</p>" if a.get('kurzantwort') else '', a['content_html'],
|
||||
f"<h2>{a.get('faq_ueberschrift') or 'Häufige Fragen'}</h2>\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'))
|
||||
Reference in New Issue
Block a user