collect-five-topic-experiences-20261111.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. """Focused discovery for actual dormitory, late-night and flavor experiences."""
  2. from concurrent.futures import ThreadPoolExecutor, as_completed
  3. import importlib.util
  4. import json
  5. from pathlib import Path
  6. ROOT=Path(__file__).resolve().parents[1]
  7. spec=importlib.util.spec_from_file_location('su',ROOT/'scripts/collect-five-topic-supplement.py')
  8. m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
  9. WORK=ROOT/'work/five-topic-research-20261111'
  10. m.WORK=WORK;m.PUBLIC=WORK/'sources';m.SEARCH=WORK/'search';m.base.PUBLIC=m.PUBLIC
  11. JOBS=[('student','宿舍 泡面 体验 site:post.smzdm.com'),
  12. ('student','夜宵 拌面 试吃 site:post.smzdm.com'),
  13. ('novelty','冬阴功 方便面 试吃 site:post.smzdm.com'),
  14. ('novelty','香菜 拌面 试吃 site:post.smzdm.com')]
  15. def main():
  16. state={'status':'running','sources':[],'rejected':[]};candidates=[]
  17. for i,(topic,q) in enumerate(JOBS,110):
  18. try:candidates.extend(m.search(i,topic,q))
  19. except Exception as e:
  20. state['rejected'].append({'query':q,'reason':str(e)})
  21. if 'VERIFICATION' in str(e):break
  22. with ThreadPoolExecutor(max_workers=2) as pool:
  23. tasks={pool.submit(m.collect,r):r for r in candidates}
  24. for f in as_completed(tasks):
  25. try:
  26. r=f.result();r['collectionDirectory']='sources';state['sources'].append(r)
  27. except Exception as e:state['rejected'].append({'url':tasks[f]['url'],'reason':str(e)})
  28. m.base.save(WORK/'experience-collection-result.json',state)
  29. print(json.dumps({'readable':len(state['sources']),'rejected':len(state['rejected'])}),flush=True)
  30. state.update(status='awaiting-semantic-review',candidates=len(candidates));m.base.save(WORK/'experience-collection-result.json',state)
  31. if __name__=='__main__':main()