#!/usr/bin/env python3
"""Reproduce two descriptive tables from the fixed public reference edition.

Usage: python3 reproduce-reference-edition-2026-10-28.py DIRECTORY
Put the ten fixed JSON files in DIRECTORY. This script has no network access,
installs nothing and writes no files. It does not reproduce the historical
September report. Existing source rights and reuse limits remain unchanged.
"""
from collections import Counter
from pathlib import Path
import hashlib,json,sys
EXPECTED_FILES = {'state-of-minnesota-creators-2026.json': 'f516209842c78a3515cbdd9875fe1100e94f992bee110b88892a07dc9942838e', 'minnesota-creator-index-2026.json': '35796f5475b2850754cd9b7435c45a458f96b47a8aa57ae70109d6fc2651b70a', 'famous-people-minnesota-2026.json': 'd9b6e6d80794c248b8a4139637eda9c2680f6b47690f479d6a90bf0c38c25f3d', 'minnesota-creators-2026.json': '668b4bfbe392047a59621c573dda9bb75f1b5025a003fd5c94986840fad49e88', 'minnesota-internet-personalities-2026.json': '611ab00888ed849c513211caa5b8544d45fa1d9015419a16fe1036be08bb960c', 'minnesota-youtube-creators-2026.json': '0cd0c12afe106c68d9d1ddee7042f32f398b07ed7cb27a288bd926193ba8badb', 'minnesota-tiktok-creators-2026.json': '982c4b50c65d3b9bb62e222c5bf81c26b736eb0b3a3e22d60dbe47fb9af6171b', 'minnesota-instagram-creators-2026.json': 'cf369fc282c875db0503501a49a65d0b90052d2970df1a7dcc0224828311c0b6', 'minnesota-facebook-creators-2026.json': '6055b7b6a45f8086ae31d4154e3dd93f0c1f06bf2b6fea0e4b138f2f1a5ea7f3', 'minneapolis-twin-cities-creators-2026.json': 'eb49a6c02ca80b02e405968e55250701626d0474879805659f04051f9979e2b8'}
def calculate(folder):
 data={}
 for name,digest in EXPECTED_FILES.items():
  raw=(folder/name).read_bytes()
  if hashlib.sha256(raw).hexdigest()!=digest:raise ValueError('Wrong edition or changed file: '+name)
  data[name]=json.loads(raw)
 roster=data['minnesota-creators-2026.json']['records'];core=data['minnesota-creator-index-2026.json']['records'];states=Counter(r['status']for r in core)
 if set(states)!={'COMPLETE','INCOMPLETE'}:raise ValueError('Unexpected Core 4 status vocabulary')
 platforms={'Core 4':{'ranked_or_complete':states['COMPLETE'],'partial_or_incomplete':states['INCOMPLETE']}}
 for key,name in [('YouTube','youtube'),('TikTok','tiktok'),('Instagram','instagram'),('Facebook','facebook')]:
  d=data['minnesota-'+name+'-creators-2026.json'];platforms[key]={'ranked_or_complete':len(d['ranked_creators']),'partial_or_incomplete':len(d['partially_verified_creators'])}
 return {'edition':'reference-2026-10-29-reliability','scope':'Counts of the bounded fixed public rosters; not population, growth, unique audience or economic estimates.','geography':dict(Counter(r['geographic_scope']for r in roster)),'record_types':dict(Counter(r['entity_type']for r in roster)),'platforms':platforms,'historical_report':'Not reproduced: these current editions are not the complete historical input set.','verified_sha256':EXPECTED_FILES}
if __name__=='__main__':
 if len(sys.argv)!=2:raise SystemExit('Pass the directory containing the ten fixed JSON files.')
 try:print(json.dumps(calculate(Path(sys.argv[1])),ensure_ascii=False,indent=2))
 except (OSError,ValueError,KeyError)as e:raise SystemExit('Cannot reproduce this edition: '+str(e))
