topic_group_queue.py 631 B

1234567891011121314151617181920212223242526
  1. import yaml
  2. from utils.project_paths import config_dir
  3. class TopicGroup:
  4. def __init__(self, config_path=f"{config_dir}/topic_map.yaml"):
  5. with open(config_path, "r") as f:
  6. data = yaml.safe_load(f)
  7. self.topics = data.get("topics", []) # 直接获取 topic 列表
  8. def __iter__(self):
  9. """支持迭代遍历 topics"""
  10. return iter(self.topics)
  11. def __len__(self):
  12. return len(self.topics)
  13. def __str__(self):
  14. return str(self.topics)
  15. if __name__ == '__main__':
  16. tg = TopicGroup()
  17. for i in tg:
  18. mmode = i.split("_")[1]
  19. print(mmode)