Files
dj/model-bridge/audit_data.py
T

16 lines
1.3 KiB
Python

import hashlib,json,sqlite3,sys
from pathlib import Path
root=Path(__file__).resolve().parent.parent
with sqlite3.connect((root/'huobao-data/huobao.sqlite3').as_uri()+'?mode=ro',uri=True) as db:
db.row_factory=sqlite3.Row
report={'integrity':db.execute('PRAGMA quick_check').fetchone()[0],'tables':{}}
for table in ('dramas','episodes','storyboards','characters','scenes','props','ai_service_configs','style_presets'):
rows=[dict(row) for row in db.execute('SELECT * FROM '+table+' ORDER BY id')]
report['tables'][table]={'count':len(rows),'ids':[r['id'] for r in rows],
'sha256':hashlib.sha256(json.dumps(rows,sort_keys=True,ensure_ascii=False).encode()).hexdigest()}
if rows and 'deleted_at' in rows[0]: report['tables'][table]['active']=sum(not r.get('deleted_at') for r in rows)
report['media']={p.relative_to(root/'huobao-data').as_posix():hashlib.sha256(p.read_bytes()).hexdigest() for p in (root/'huobao-data/static').rglob('*') if p.is_file()}
if len(sys.argv)>1: (root/'integration-work'/sys.argv[1]).write_text(json.dumps(report,indent=2))
print(json.dumps({k:{a:b for a,b in v.items() if a in ('count','active')} for k,v in report['tables'].items()},ensure_ascii=False))
print('integrity:',report['integrity'],'media files:',len(report['media']))