get_top_article.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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(account_name: str, uid_cnt_threshold: int = 100) -> str:
  16. odps_query = f"""
  17. SELECT title
  18. ,COUNT(1) AS uid_cnt
  19. FROM article_union_id_mapper
  20. WHERE union_id IN (
  21. SELECT union_id
  22. FROM gzh_fans_info
  23. WHERE account_name = '{account_name}'
  24. AND dt = MAX_PT('gzh_fans_info')
  25. )
  26. AND accountname != '{account_name}'
  27. GROUP BY title
  28. HAVING uid_cnt > {uid_cnt_threshold};
  29. """
  30. return odps_query