import re, sys
S='/tmp/claude-0/-home-claude/412360f8-9c0b-55d1-a24e-f4646e8683bb/scratchpad'
Y, ms = sys.argv[1], sys.argv[2:]
for m in ms:
out=[]
for b in re.split(r'(?m)^(?==== )', open(f'{S}/rf_{Y}_{m}.txt').read()):
l=b.rstrip('\n').split('\n')
if len(l)<3 or 'KI-WEEKLY' in l[0]: out.append(b); continue
i=[n for n,x in enumerate(l) if x.startswith('DE: ')][0]
de=l[i:]
if ('Wöchentlicher' in de[0] and 'report' in de[0].lower()) or 'Status-Update' in de[0]:
bul=[x[2:].strip() for x in de if x.startswith('• ')]
src=[x.replace('
','').strip() for x in l[2:i] if x.replace('
','').strip() and not re.search(r'[.:!?]\s*$', x.replace('
','').strip()) and len(x.split())<=7]
src=[re.sub(r'\t',', ',x).strip() for x in src]
norm=lambda x: re.sub(r'[\s,]+',' ',x).strip()
ok = [norm(x) for x in bul]==[norm(x) for x in src]
print(m, l[0].split()[1], 'WEEKLY', 'OK' if ok else f'DIFF {set(src)^set(bul)}')
continue
out.append(b)
open(f'{S}/rg_{Y}_{m}.txt','w').write(''.join(out))