|
|
@@ -46,31 +46,6 @@ class BaseOffRecommendUtils:
|
|
|
unsafe_titles_set.update(apollo_bad_titles)
|
|
|
return unsafe_titles_set
|
|
|
|
|
|
- # 获取账号的 Top 文章
|
|
|
- async def get_account_top_articles(
|
|
|
- self, gh_id: str, strategy: str
|
|
|
- ) -> List[Dict[str, str]]:
|
|
|
- match strategy:
|
|
|
- # 后续拓展策略
|
|
|
- case _:
|
|
|
- query = GetTopArticleStrategy.base()
|
|
|
-
|
|
|
- top_articles = await LongArticleDatabaseMapper.Recommend.get_top_articles(
|
|
|
- pool=self.pool, query=query, gh_id=gh_id
|
|
|
- )
|
|
|
-
|
|
|
- return top_articles
|
|
|
-
|
|
|
- # 获取标题的推荐文章
|
|
|
- async def get_recommend_articles(self, title: str, strategy: str) -> List:
|
|
|
- match strategy:
|
|
|
- # 后续拓展策略
|
|
|
- case _:
|
|
|
- query = I2I.base(title)
|
|
|
-
|
|
|
- recommend_articles = await self.read_from_odps(query)
|
|
|
- return recommend_articles
|
|
|
-
|
|
|
# 获取一批标题的推荐标题
|
|
|
async def get_recommend_articles_for_batch_titles(
|
|
|
self, title_list: List[str], strategy: str
|
|
|
@@ -82,8 +57,6 @@ class BaseOffRecommendUtils:
|
|
|
case _:
|
|
|
query = I2I.batch_base(title_list)
|
|
|
|
|
|
- print(query)
|
|
|
-
|
|
|
recommend_articles = await self.read_from_odps(query)
|
|
|
return recommend_articles
|
|
|
|
|
|
@@ -156,8 +129,23 @@ class BaseOfflineRecommend(BaseOffRecommendUtils):
|
|
|
published_titles: Set[str],
|
|
|
):
|
|
|
gh_id: str = account_info["gh_id"]
|
|
|
- top_articles = await self.get_account_top_articles(gh_id, strategy)
|
|
|
- top_titles = [i["title"] for i in top_articles]
|
|
|
+ account_name: str = account_info["account_name"]
|
|
|
+
|
|
|
+ match strategy:
|
|
|
+ case "v1":
|
|
|
+ odps_query = GetTopArticleStrategy.strategy_v1(account_name)
|
|
|
+ top_articles = await self.read_from_odps(odps_query)
|
|
|
+ top_titles = [i.title for i in top_articles]
|
|
|
+
|
|
|
+ case "base":
|
|
|
+ mysql_query = GetTopArticleStrategy.base()
|
|
|
+ top_articles = await LongArticleDatabaseMapper.Recommend.get_top_articles(
|
|
|
+ pool=self.pool, query=mysql_query, gh_id=gh_id
|
|
|
+ )
|
|
|
+ top_titles = [i["title"] for i in top_articles]
|
|
|
+
|
|
|
+ case _:
|
|
|
+ return []
|
|
|
|
|
|
recommend_articles = await self.get_recommend_articles_for_batch_titles(
|
|
|
top_titles, strategy
|