test_db.py
3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import time
import traceback
from mysql.connector import pooling
from log.logger import log
from mysql_service import funasr_db
from mysql_service import MysqlHelper
from config import DbConect
from mysql_service import mysql_utils
from mysql_service.mysql_pool import ConnPool
from config.config import ConfigInfo
consuming_start_time = time.perf_counter()
# db = MysqlHelper.MysqlHelper(
# DbConect.ali_asr_model
# )
task_id = str("63764ce2-e5cb-11ee-928c-b083fec01e48")
url = "https://smartcard-1253080096.cos.ap-guangzhou.myqcloud.com/audio/4827E2F0CD24_1709084561_4827E2F0CD24-1709084561.MP3"
# res = funasr_db.insert_ali_asr_model_res(task_id, url)
# print(f"res:{res}")
sql = "INSERT INTO dj_smartcarlife.ali_asr_model_res (task_id,file_url,task_status) VALUES (" \
"'47f9402c-e5cc-11ee-928c-b083fec01e48','https://img01.glsx.com.cn/weapp/resource/wav/122m4a.wav',0);"
# select_res = mysql_utils.execute_sql("select * from ali_asr_model_res aamr;")
# print(select_res)
for i in range(1):
res1 = funasr_db.insert_ali_asr_model_res(task_id, url)
print("res1:%s" % res1)
res2 = funasr_db.update_ali_asr_model_res(task_id, sql, int(time.time()))
print("res2:%s" % res2)
res3 = funasr_db.select_ali_asr_model_res(task_id)
print("res3:%s" % res3)
res4 = funasr_db.select_ali_asr_model_wait()
print("res4:%s" % res4)
try:
# time.sleep(2)
execute_time = time.perf_counter() - consuming_start_time
log.info(
f"Function create_upload_file executed in {execute_time} s"
)
# funasr_db.update_ali_asr_model_res(task_id, task_id, int((execute_time * 1000)))
# if res is None or isinstance(res, bool) or len(res) < 1:
# print("======")
except Exception as e:
print(f"e:{traceback.format_exc()}")
# funasr_db.update_ali_asr_model_res_fail(task_id, str(traceback.format_exc()))
import json
# 定义要执行的SQL语句
# SQL = """
# select * from sys_order_file_ocr_sn sofon limit 5
# """
# # 执行SQL语句
# cursor_dev.execute(SQL)
#
# # 获取查询结果
# result = cursor_dev.fetchall()
#
# class Config:
# DEBUG = False
# env = 'dev'
# # 数据库连接配置
# host='192.168.3.227'
# port = 3306
# user = 'dev_user'
# password = 'df234fl'
# database = 'dj_smartcarlife'
# # Kafka consumer配置
# kafka_consumer_bootstrap_servers = '192.168.3.131:9092'
# kafka_consumer_group_id = 'ocr_consumer_dev'
# kafka_consumer_auto_offset_reset = 'earliest'
# kafka_consumer_topic = 'ocr_topic'
# charset = 'utf8'
#
#
# # 创建连接池对象
# connection_pool = pooling.MySQLConnectionPool(
# pool_name="mypool",
# pool_size=32,
# pool_reset_session=True,
# host=Config.host,
# port=Config.port,
# database=Config.database,
# user=Config.user,
# password=Config.password,
# autocommit=True,
# )
#
# # 从连接池获取连接
# def get_connection():
# log.info("connection_pool size:" + str(connection_pool._cnx_queue.qsize()))
# # 从连接池获取连接
# return connection_pool.get_connection()
#
#
# def execute_sql(sql):
# try:
# conn = get_connection()
# cursor = conn.cursor()
# cursor.execute(sql)
# conn.commit()
# log.info("sql 执行结束")
# except Exception as msg:
# log.error("sql执行Exception: " + str(msg))
# finally:
# cursor.close()
# conn.close()
#
# SQL = "select * from sys_order_ocr_vin_result"
# res = execute_sql(SQL)
# print(res)
#