luojunhui 2 mesiacov pred
rodič
commit
1528fa0fe7

+ 5 - 2
applications/asyncDB.py

@@ -3,6 +3,8 @@
 """
 import aiomysql
 
+from aiomysql.cursors import Cursor
+
 from applications import log
 from config import env
 
@@ -68,14 +70,15 @@ class AsyncMySQLClient(object):
         self.app.mysql_pool.close()
         await self.app.mysql_pool.wait_closed()
 
-    async def asyncSelect(self, sql):
+    async def asyncSelect(self, sql, cursor_type=Cursor):
         """
         select method
         :param sql:
+        :param cursor_type:
         :return:
         """
         async with self.app.mysql_pool.acquire() as conn:
-            async with conn.cursor() as cursor:
+            async with conn.cursor(cursor_type) as cursor:
                 await cursor.execute(sql)
                 result = await cursor.fetchall()
                 return result

+ 2 - 2
config/__init__.py

@@ -3,8 +3,8 @@
 config
 """
 # 环境
-# env = "prod"
-env = "dev"
+env = "prod"
+# env = "dev"
 
 # 视频表
 daily_video = "top_videos_daily"

+ 2 - 1
deal/__init__.py

@@ -1,4 +1,5 @@
 """
 @author: luojunhui
 """
-from .ArticleRank import tempServer
+from .ArticleRank import tempServer
+from .reacll_articles import generate_response_v2

+ 54 - 0
deal/reacll_articles.py

@@ -0,0 +1,54 @@
+"""
+@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
+
+
+
+

+ 14 - 0
routes/__init__.py

@@ -12,6 +12,7 @@ from .recallPQVideos import recallPQVideos
 from .process_killer import kill_task_by_name
 
 from deal import tempServer
+from deal import generate_response_v2
 
 
 TL_blueprint = Blueprint("TouLiu", __name__)
@@ -89,6 +90,19 @@ def Routes(db_client):
         response = ts.chooseCards()
         return jsonify(response)
 
+    @TL_blueprint.route("/VideoRank2", methods=['POST'])
+    async def rank_v2():
+        """
+        use db rather than config
+        """
+        data = await request.get_json()
+        gh_id = data['ghId']
+        response = await generate_response_v2(
+            gh_id=gh_id,
+            db_client=db_client
+        )
+        return jsonify(response)
+
     @TL_blueprint.route("/KILL", methods=['GET'])
     async def kill():
         """