reacll_articles.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. @author: luojunhui
  3. """
  4. from aiomysql.cursors import DictCursor
  5. async def get_account_reply(db_client, gh_id):
  6. """
  7. 获取公众号回复文章和视频
  8. """
  9. sql = f"""
  10. select `group_index` , `msg_type` , `video_index` , `mini_video_id` , `mini_page_path` , `news_description` , `new_url` , `title` , `cover_url`
  11. from touliu_auto_reply
  12. where `gh_id` = '{gh_id}';
  13. """
  14. reply_list = await db_client.asyncSelect(
  15. sql=sql,
  16. cursor_type=DictCursor
  17. )
  18. return reply_list
  19. async def generate_response_v2(gh_id, db_client):
  20. """
  21. 生成回复文章和视频
  22. """
  23. reply_list = await get_account_reply(db_client, gh_id)
  24. if not reply_list:
  25. return None
  26. group_index_list = list(set([i['group_index'] for i in reply_list]))
  27. L = []
  28. for index in sorted(group_index_list):
  29. obj = {
  30. "groupIndex": index,
  31. "msgDataList": [
  32. {
  33. 'coverUrl': i['cover_url'],
  34. "miniAppId": 'wxbdd2a2e93d9a6e25' if i['msg_type'] == 1 else "",
  35. "miniPagePath": i['mini_page_path'],
  36. "miniVideoId": str(i['mini_video_id']) if i['mini_video_id'] else None,
  37. "msgType": i['msg_type'],
  38. "newsDescription": i['news_description'],
  39. "newsUrl": i['new_url'],
  40. "title": i['title'],
  41. }
  42. for i in reply_list
  43. ]
  44. }
  45. L.append(obj)
  46. return L