Files
Skrift-Auto-Article/build/luecken.py

15 lines
954 B
Python

# -*- 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))