from pathlib import Path import sqlite3,shutil,json from PIL import Image root=Path('D:/web/dj');data=root/'integration-work/hd-test-references' data.mkdir(exist_ok=True) assert not (data/'huobao.sqlite3').exists(), 'Existing fixture: do not overwrite' with sqlite3.connect(root/'huobao-data/huobao.sqlite3') as src,sqlite3.connect(data/'huobao.sqlite3') as db: src.backup(db) db.execute('DELETE FROM sys_task') db.execute("UPDATE ai_service_configs SET base_url='http://127.0.0.1:18887/v1',api_key='reference-test-key'") for table in ['characters','scenes','props']: db.execute(f"UPDATE {table} SET final_prompt='Reference fixture: studio photograph, retain identity and shape.'") for image,local in db.execute(f'SELECT image_url,local_path FROM {table}'): for value in (image,local): if value and value.lstrip('/').startswith('static/'): rel=Path(value.lstrip('/'));source=root/'huobao-data'/rel;target=data/rel if source.is_file():target.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(source,target) for table,id in [('characters',26),('characters',27),('scenes',22),('props',1)]: db.execute(f'UPDATE {table} SET deleted_at=NULL WHERE id=?',(id,)) db.execute('UPDATE props SET drama_id=6 WHERE id=1') db.execute("INSERT OR IGNORE INTO episode_props(episode_id,prop_id,created_at) VALUES(7,1,datetime('now'))") for name,color in [('red',(210,30,30)),('blue',(30,40,220)),('green',(25,190,40))]:Image.new('RGB',(256,256),color).save(data/(name+'.png')) print(str(data))