"""Read existing sample files; write reproducible structural findings. Requires installed PyMuPDF."""
from pathlib import Path
import hashlib, json, zipfile, xml.etree.ElementTree as E
import fitz
ROOT=Path(__file__).resolve().parents[3]
OUT=Path(__file__).resolve().parent
BASE=ROOT/'public/seo-assets/accessibility-sample-deck'
ns={'a':'http://schemas.openxmlformats.org/drawingml/2006/main','p':'http://schemas.openxmlformats.org/presentationml/2006/main'}
files=[]
for ext in ('pptx','pdf'):
 p=BASE/f'accessibility-sample-deck.{ext}'
 files.append({'path':str(p.relative_to(ROOT)), 'bytes':p.stat().st_size,'sha256':hashlib.sha256(p.read_bytes()).hexdigest()})
z=zipfile.ZipFile(BASE/'accessibility-sample-deck.pptx')
slides=[]
for i in range(1,8):
 r=E.fromstring(z.read(f'ppt/slides/slide{i}.xml'))
 shapes=[]
 for s in r.find('p:cSld/p:spTree',ns):
  if s.tag.split('}')[-1] in ('nvGrpSpPr','grpSpPr'):continue
  shapes.append({'kind':s.tag.split('}')[-1], 'text':' | '.join(t.text or '' for t in s.findall('.//a:t',ns))})
 notes=E.fromstring(z.read(f'ppt/notesSlides/notesSlide{i}.xml'))
 slides.append({'slide':i,'title_placeholders':len(r.findall('.//p:ph[@type="title"]',ns)), 'picture_count':len(r.findall('.//p:pic',ns)), 'bullet_paragraphs':len(r.findall('.//a:buChar',ns)), 'table_properties':[t.attrib for t in r.findall('.//a:tblPr',ns)],'shape_order_xml':shapes,'notes_text':[t.text for t in notes.findall('.//a:t',ns)],'explicit_run_languages':sorted(set(t.get('lang') for t in r.findall('.//a:rPr',ns) if t.get('lang')))})
pdf=fitz.open(BASE/'accessibility-sample-deck.pdf')
catalog=pdf.xref_object(pdf.pdf_catalog())
report={'inspected_on':'2026-11-04','method':'ZIP/XML via Python standard library; PDF objects, page text and painted images via installed PyMuPDF. No OCR. No re-export.', 'files':files,'pptx':{'slides':slides,'media_files':[n for n in z.namelist() if n.startswith('ppt/media/') and not n.endswith('/')], 'core_properties_xml':z.read('docProps/core.xml').decode()},'pdf':{'metadata':pdf.metadata,'catalog':catalog,'structure_tree_root_present':'/StructTreeRoot' in catalog,'pages':[{'page':i+1,'extracted_text_characters':len(p.get_text()),'painted_image_count':len(p.get_image_info()),'link_count':len(p.get_links())} for i,p in enumerate(pdf)]},'not_tested':['PowerPoint Accessibility Checker','screen readers','desktop opening/rendering','visual contrast across slides','alt-text and captions round-trip: sample has no images or media','pixel-perfect PPTX, PNG and built-in HTML exports: not present in sample folder']}
(OUT/'inspection.json').write_text(json.dumps(report,indent=2)+'\n')
print(json.dumps({'slides':len(slides),'missing_title':[s['slide'] for s in slides if not s['title_placeholders']], 'pdf_pages':report['pdf']['pages']},indent=2))
