import sys,re t=open(sys.argv[1]).read().split("=====FINAL=====")[-1] tc=t.replace(",","") gross_ok=all(g in tc for g in ["1440.00","540.00","2760.00","216.00","1170.60"]) and all(v in tc for v in ["240.00","90.00","460.00","36.00","195.10"]) # overdue section: text between 'overdue' heading and 'total' m=re.search(r"(?is)overdue invoices?(.*?)total gross",t); sec=m.group(1) if m else "" od=sorted(set(i for l in sec.splitlines() if l.strip()[:1] in "-*|1234567890" and not re.search(r"(?i)\bnot\b",l) for i in re.findall(r"INV-10\d",l))) over_ok= od==["INV-101","INV-102","INV-105"] tot_ok="3150.60" in tc em=t.split("ubject")[-1] if "ubject" in t else "" mail_ok=("Tyne" in em and "INV-105" in em and "1170.60" in em.replace(",","")) print(f"vat_gross={gross_ok} overdue={over_ok} {od} total={tot_ok} chaser={mail_ok}")