get_top_article.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. from .base import BaseStrategy
  2. class GetTopArticleStrategy(BaseStrategy):
  3. @staticmethod
  4. def base() -> str:
  5. query = """
  6. SELECT title, sum(view_count) as total_view_count, sum(fans) as total_fan_count
  7. FROM datastat_sort_strategy
  8. WHERE position = 1 and gh_id = %s AND date_str >= '20250501' AND view_count > 1000
  9. GROUP BY title
  10. ORDER BY sum(view_count) / sum(fans) DESC
  11. LIMIT 25;
  12. """
  13. return query
  14. @staticmethod
  15. def strategy_v1() -> str:
  16. query = """
  17. SELECT title, sum(view_count) as total_view_count, sum(fans) as total_fan_count
  18. FROM datastat_sort_strategy
  19. WHERE position = 1 and gh_id = %s AND date_str >= '20250501' AND view_count > 1000
  20. GROUP BY title
  21. ORDER BY sum(view_count) / sum(fans) DESC
  22. LIMIT 25;
  23. """
  24. return query
  25. @staticmethod
  26. def strategy_v2() -> str:
  27. query = """
  28. SELECT date_str, title, view_count from datastat_sort_strategy where position = 1 and gh_id = %s
  29. """
  30. return query