liyuyi@c-top.com.cn 3 anos atrás
pai
commit
a305751093

+ 1 - 1
common_func.py

@@ -13,7 +13,7 @@ import base64
 # 创建数据库连接引擎
 def get_db_engine(db_info):
     db_con_str = 'mysql+pymysql://%s:%s@%s:%d/%s' % \
-                 (db_info['username'],
+                 (db_info['user'],
                   parse.quote_plus(db_info['password']),
                   db_info['host'],
                   db_info['port'],

+ 5 - 5
config/config.yaml

@@ -13,7 +13,7 @@ source_name_map:
 # jeecg-boot 生产数据库
 jeecg_boot_product_db:
   host: 139.186.27.96
-  username: data
+  user: data
   password: hcst@2021
   port: 3390
   database: jeecg-boot
@@ -22,7 +22,7 @@ jeecg_boot_product_db:
 # jeecg-boot 测试数据库
 jeecg_boot_dev_db:
   host: 139.186.27.96
-  username: data
+  user: data
   password: hcst@2021
   port: 3390
   database: jeecg-boot
@@ -31,7 +31,7 @@ jeecg_boot_dev_db:
 # db_ai_word 测试数据库
 ai_word_dev_db:
   host: 139.186.165.84
-  username: hcst
+  user: hcst
   password: hcst@2020
   port: 3306
   database: db_ai_word
@@ -41,7 +41,7 @@ ai_word_dev_db:
 # db_ai_word 生产数据库
 ai_word_product_db:
   host: 139.186.165.84
-  username: hcst
+  user: hcst
   password: hcst@2020
   port: 3306
   database: db_ai_word
@@ -51,7 +51,7 @@ ai_word_product_db:
 # 本地数据库 mysql
 local_db:
   host: 192.168.1.193
-  username: root
+  user: root
   password: root@123
   port: 3306
   database: mysql

+ 1 - 1
get_material_and_script/get_material_from_kuaishou_kaiyan.py

@@ -88,7 +88,7 @@ class GetMaterialFromKuaishouKaiyan(object):
 
 
 if __name__ == '__main__':
-    db_info = {'username': 'hcst',
+    db_info = {'user': 'hcst',
                'password': 'hcst@2020',
                'host': '139.186.165.84',
                'port': 3306,

+ 1 - 1
get_material_and_script/get_material_from_ocean_engine.py

@@ -145,7 +145,7 @@ class GetMaterialFromOceanEngine(object):
 
 
 if __name__ == '__main__':
-    db_info = {'username': 'hcst',
+    db_info = {'user': 'hcst',
                'password': 'hcst@2020',
                'host': '139.186.165.84',
                'port': 3306,

+ 61 - 2
main.py

@@ -1,9 +1,11 @@
 import datetime
+import hashlib
+import uuid
 from concurrent.futures import ThreadPoolExecutor
 from io import BytesIO
 from typing import Optional, List
 from urllib.parse import quote
-import hashlib
+import pymysql
 import pandas as pd
 import uvicorn
 import yaml
@@ -13,7 +15,7 @@ from fastapi.responses import StreamingResponse
 from pydantic import BaseModel, Field
 
 from asr_client import send_asr_request, send_task_request
-from common_func import get_db_engine
+from common_func import get_db_engine, mysql_replace_into
 from config.url import toutiao_static_video_url
 from database import insert, update, query, Task
 
@@ -162,6 +164,63 @@ def export_excel(item: List[QueryWordItem]):
     return None
 
 
+class ScriptConfig(BaseModel):
+    query_word_lst: List = Field(..., description="关键词组")
+    operator: str = Field(..., description="操作者")
+
+
+@app.post('/get_script_config_lst/')
+def get_script_config_lst():
+    pass
+
+
+@app.post('/add_script_config/')
+def add_script_config(item: ScriptConfig):
+    config_id = str(uuid.uuid4())
+    config_lst = []
+    for query_word in item.query_word_lst:
+        sql = f"select * from ctop_ai_query_word where query_word = '{query_word}'"
+        query_word_df = pd.read_sql(sql, ai_word_engine)
+        if not query_word_df.empty:
+            # 更新 ctop_ai_query_word
+            query_word_id = query_word_df.query_word_id.values[0]
+            script_config_conn_num = query_word_df.script_config_conn_num.values[0] + 1
+            db_con = pymysql.connect(**config['ai_word_dev_db'])
+            db_cur = db_con.cursor()
+            sql = f"update ctop_ai_query_word set script_config_conn_num = {script_config_conn_num} where query_word_id = '{query_word_id}'"
+            db_cur.execute(sql)
+            db_con.commit()
+            db_con.close()
+            # update_query_word_df = pd.DataFrame([{"query_word_id": query_word_id,
+            #                                       "query_word": query_word,
+            #                                       "script_conn_num": script_conn_num}])
+            # update_query_word_df.to_sql(name="ctop_ai_query_word",
+            #                             con=ai_word_engine,
+            #                             if_exists="append",
+            #                             method=mysql_replace_into,
+            #                             index=False)
+
+        else:
+            query_word_id = str(uuid.uuid4())
+            new_query_word_df = pd.DataFrame([{"query_word_id": query_word_id, "query_word": query_word, "script_config_conn_num": 1}])
+            new_query_word_df.to_sql(name="ctop_ai_query_word",
+                                     con=ai_word_engine,
+                                     if_exists="append",
+                                     index=False)
+
+        config_lst.append({"config_id": config_id, "query_word_id": query_word_id})
+
+    # 新增配置记录插入到 ctop_ai_script_query_word_config
+    config_df = pd.DataFrame(config_lst)
+    config_df['operator'] = item.operator
+    config_df['operate_type'] = 1
+    config_df.to_sql(name="ctop_ai_script_query_word_config",
+                     con=ai_word_engine,
+                     if_exists='append',
+                     index=False)
+    return {"code": 0, "message": "success"}
+
+
 if __name__ == '__main__':
     # 1 读取配置文件
 

+ 3 - 4
time_task/tmp_task.py

@@ -13,7 +13,6 @@ sys.path.append(project_root_path)
 
 from common_func import get_db_engine, get_logger
 from get_material_and_script.get_script_from_tengxunyun import GetScriptFromTengXunYunServer
-from get_material_and_script.get_material_from_huichuang import GetMaterialFromHuiChuang
 
 if __name__ == '__main__':
     # 创建日志对象
@@ -44,9 +43,10 @@ if __name__ == '__main__':
     # `channel_type` int(2) DEFAULT '0' COMMENT '0:自产 1:素造',
     sql = f"select signature,url video_url, channel_type from ctop_kuaishou_video_get where account_id in " \
           f"(select account_id from ctop_user_allocation where project_id = {project_id}) " \
-          f"and channel_type = 0 and stat_date>='2021-08-01' group by signature limit 100"
+          f"and channel_type = 0 and stat_date>='2021-08-01' group by signature"
     df = pd.read_sql(sql, jeecg_boot_engine)
     df['query_word'] = query_word
+    df['project_id'] = project_id
     df['stat_date'] = datetime.date.today().strftime("%Y-%m-%d")
 
     df.to_sql(name="ctop_ai_video_info_from_huichuang",
@@ -63,8 +63,7 @@ if __name__ == '__main__':
     inst = None
 
     # 2 调用腾讯云的语音转脚本服务,获取脚本
-    if not df.emtpy:
-        inst.video_df = inst.video_df[~inst.video_df.signature.isnull()]
+    if not df.empty:
         get_script_ins = GetScriptFromTengXunYunServer(logger=logger,
                                                        db_engine=ai_word_engine,
                                                        task_df=df[['signature', 'video_url']],