|  | @@ -0,0 +1,60 @@
 | 
	
		
			
				|  |  | +"""
 | 
	
		
			
				|  |  | +@author: luojunhui
 | 
	
		
			
				|  |  | +@software: vscode
 | 
	
		
			
				|  |  | +@file: rank_by_fission_on_read.py
 | 
	
		
			
				|  |  | +@time: 2025-01-04
 | 
	
		
			
				|  |  | +"""
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +from typing import Dict, List
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +from aiomysql.cursors import DictCursor
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +async def get_content_id_fission_info(content_id_tuple: tuple[str], db_client, video_limit: int) -> List[Dict]:
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +    获取内容id的裂变/阅读信息
 | 
	
		
			
				|  |  | +    :param content_id:
 | 
	
		
			
				|  |  | +    :return:
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +    select_sql = f"""
 | 
	
		
			
				|  |  | +        SELECT 
 | 
	
		
			
				|  |  | +            l.oss_name, l.read_total, l.fission_level_0_total, l.fission_0_on_read 
 | 
	
		
			
				|  |  | +        FROM 
 | 
	
		
			
				|  |  | +            long_articles_videos_fission_info l 
 | 
	
		
			
				|  |  | +        LEFT JOIN 
 | 
	
		
			
				|  |  | +            article_re_match_record r 
 | 
	
		
			
				|  |  | +            ON l.oss_name = r.oss_path
 | 
	
		
			
				|  |  | +        WHERE 
 | 
	
		
			
				|  |  | +            l.content_id IN {content_id_tuple}
 | 
	
		
			
				|  |  | +            AND r.oss_path IS NULL 
 | 
	
		
			
				|  |  | +        ORDER BY l.fission_0_on_read DESC 
 | 
	
		
			
				|  |  | +        LIMIT {video_limit};
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +    response = await db_client.async_select(select_sql, DictCursor)
 | 
	
		
			
				|  |  | +    print("get_content_id_fission_info", response)
 | 
	
		
			
				|  |  | +    return response
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +async def get_history_content_ids(content_id: str, db_client) -> tuple[str]:
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +    Retrieve historical content IDs related to the given content ID.
 | 
	
		
			
				|  |  | +    :param content_id: The ID of the content for which related content IDs are to be retrieved.
 | 
	
		
			
				|  |  | +    :param db_client: The database client used to execute the query.
 | 
	
		
			
				|  |  | +    :return: A tuple containing the historical content IDs.
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +    select_sql = f"""
 | 
	
		
			
				|  |  | +        SELECT 
 | 
	
		
			
				|  |  | +            DISTINCT c2.content_id
 | 
	
		
			
				|  |  | +        FROM crawler_produce_id_map c
 | 
	
		
			
				|  |  | +        JOIN article_pool_promotion_source ap1 
 | 
	
		
			
				|  |  | +            ON c.channel_content_id = ap1.channel_content_id
 | 
	
		
			
				|  |  | +        JOIN article_pool_promotion_source ap2
 | 
	
		
			
				|  |  | +            ON ap1.root_produce_content_id = ap2.root_produce_content_id
 | 
	
		
			
				|  |  | +        JOIN crawler_produce_id_map c2
 | 
	
		
			
				|  |  | +            ON ap2.channel_content_id = c2.channel_content_id
 | 
	
		
			
				|  |  | +        WHERE c.content_id = '{content_id}';
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +    response = await db_client.async_select(select_sql, DictCursor)
 | 
	
		
			
				|  |  | +    print("get_history_content_ids", response) 
 | 
	
		
			
				|  |  | +    response_tuple = tuple(item["content_id"] for item in response)
 | 
	
		
			
				|  |  | +    return response_tuple
 |