aigc_mapper.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. from typing import List, Dict
  2. from app.core.database import DatabaseManager
  3. class AigcDatabaseMapper:
  4. # 从 aigc 数据库查询 channel_content_id && channel 信息
  5. @staticmethod
  6. async def fetch_channel_info(pool: DatabaseManager, content_id: str) -> List[Dict]:
  7. query = """
  8. SELECT t1.channel_content_id, t2.channel
  9. FROM produce_plan_exe_record t1 JOIN crawler_content t2 ON t1.channel_content_id = t2.channel_content_id
  10. WHERE plan_exe_id = %s;
  11. """
  12. return await pool.async_fetch(query=query, db_name="aigc", params=(content_id,))
  13. # 从 aigc 如何查询文章封面信息
  14. @staticmethod
  15. async def fetch_aigc_cover(
  16. pool: DatabaseManager, channel_content_id: str
  17. ) -> List[Dict]:
  18. """
  19. use channel_content_id to find article cover
  20. """
  21. COVER_TYPE = 2
  22. query = """
  23. SELECT image_url, oss_object_key
  24. FROM crawler_content_image
  25. WHERE channel_content_id = %s AND image_type = %s;
  26. """
  27. return await pool.async_fetch(
  28. query=query, db_name="aigc", params=(channel_content_id, COVER_TYPE)
  29. )