async_mysql_utils.py 776 B

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