Files
seo-geo-research-OPEN/scripts/rollup.py
T

23 lines
1.8 KiB
Python
Raw Normal View History

2026-10-14 10:45:26 -06:00
from pathlib import Path
import hashlib, re, json, argparse
def build(root):
root=Path(root); reports=root/'reports'; out=reports/'seo-geo-research-rollup.md'
files=sorted(p for p in reports.rglob('*.md') if p != out and 'receipts' not in p.parts and (p.name.startswith('GEO-AI-Search-Weekly-Research-Archive-') or re.match(r'\d{4}-\d{2}-\d{2}-geo-ai-search-intelligence',p.name)))
if not files: raise ValueError('No source reports; rollup unchanged')
parts=['# SEO / GEO research rollup','Chronological source record. Imported ChatGPT claims lack portable citations and remain historical, unverified evidence. New reports preserve their own completion status and source attribution. This rollup does not independently revalidate claims.','## Source inventory']
inventory=[]
for p in files:
raw=p.read_bytes(); text=raw.decode('utf-8-sig'); dates=re.findall(r'^# (\d{4}-\d{2}-\d{2})$',text,re.M)
item={'path':p.relative_to(root).as_posix(),'sha256':hashlib.sha256(raw).hexdigest(),'weekly_sections':len(dates)}; inventory.append(item)
parts.append(f"- [{p.name}]({p.relative_to(reports).as_posix()}): SHA256 `{item['sha256']}`; imported weekly sections: {len(dates)}")
for p in files: parts.extend(['---','## Source: '+p.name,p.read_text(encoding='utf-8-sig')])
content='\n\n'.join(parts)+'\n'; temp=out.with_suffix('.md.tmp'); temp.write_text(content,encoding='utf-8'); temp.replace(out)
if out.read_text(encoding='utf-8') != content: raise IOError('Readback mismatch')
if (root/'repository.json').exists():
from build_content_index import build as refresh_index
refresh_index(root)
return inventory
if __name__=='__main__':
parser=argparse.ArgumentParser(); parser.add_argument('--root',default=str(Path(__file__).resolve().parents[1])); args=parser.parse_args(); print(json.dumps(build(args.root),indent=2))