#!/usr/bin/env python3
"""usage: python3 confere.py base.md transcript.txt
Is each quoted excerpt from the source in the transcript? Exits 1 if any are missing."""
import re, sys, unicodedata
def n(s): # lowercase, no accents, no punctuation
s = unicodedata.normalize("NFD", s.lower()).encode("ascii", "ignore").decode()
return re.sub(r"\s+", " ", re.sub(r"[^a-z0-9%]+", " ", s)).strip()
base = open(sys.argv[1], encoding="utf-8").read()
tx = n(open(sys.argv[2], encoding="utf-8").read())
fora = 0
for trecho in re.findall(r'"([^"]{20,})"', base):
ok = n(trecho) in tx
fora += not ok
print("OK " if ok else "FORA", trecho[:70])
sys.exit(1 if fora else 0)