long_articles.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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]
  23. async def insert_crawler_plan(pool: DatabaseManager, data_tuple: tuple):
  24. query = """
  25. INSERT INTO article_crawler_plan (crawler_plan_id, name, create_timestamp)
  26. VALUES (%s, %s, %s);
  27. """
  28. return await pool.async_save(
  29. query=query, params=data_tuple
  30. )