long_articles.py 874 B

123456789101112131415161718192021222324252627
  1. from typing import List, Dict
  2. from app.core.database import DatabaseManager
  3. async def get_top_article_title_list(pool: DatabaseManager) -> List[Dict]:
  4. query = """
  5. select distinct title, source_id
  6. from datastat_sort_strategy
  7. where produce_plan_name = %s and source_id is not null;
  8. """
  9. return await pool.async_fetch(query=query, params=("TOP100",))
  10. async def get_hot_titles(
  11. pool: DatabaseManager, date_string: str, position: int, read_times_threshold: float
  12. ) -> List[str]:
  13. """get titles of hot articles"""
  14. query = """
  15. select distinct title
  16. from datastat_sort_strategy
  17. where position < %s and read_rate >= %s and date_str >= %s;
  18. """
  19. response = await pool.async_fetch(
  20. query=query, params=(position, read_times_threshold, date_string)
  21. )
  22. return [i["title"] for i in response]