123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- """
- @author: luojunhui
- """
- from aiomysql.cursors import DictCursor
- async def get_account_reply(db_client, gh_id):
- """
- 获取公众号回复文章和视频
- """
- sql = f"""
- select `group_index` , `msg_type` , `video_index` , `mini_video_id` , `mini_page_path` , `news_description` , `new_url` , `title` , `cover_url`
- from touliu_auto_reply
- where `gh_id` = '{gh_id}';
- """
- reply_list = await db_client.asyncSelect(
- sql=sql,
- cursor_type=DictCursor
- )
- return reply_list
- async def generate_response_v2(gh_id, db_client):
- """
- 生成回复文章和视频
- """
- reply_list = await get_account_reply(db_client, gh_id)
- if not reply_list:
- return None
- group_index_list = list(set([i['group_index'] for i in reply_list]))
- L = []
- for index in sorted(group_index_list):
- obj = {
- "groupIndex": index,
- "msgDataList": [
- {
- 'coverUrl': i['cover_url'],
- "miniAppId": 'wxbdd2a2e93d9a6e25' if i['msg_type'] == 1 else "",
- "miniPagePath": i['mini_page_path'],
- "miniVideoId": str(i['mini_video_id']) if i['mini_video_id'] else None,
- "msgType": i['msg_type'],
- "newsDescription": i['news_description'],
- "newsUrl": i['new_url'],
- "title": i['title'],
- }
- for i in reply_list
- ]
- }
- L.append(obj)
- return L
|