|
@@ -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 读取配置文件
|
|
|
|