Files
tw/scripts/check_garbled.py
2026-03-06 12:44:57 +08:00

43 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pymysql
import re
conn = pymysql.connect(
host='1.12.50.92',
port=3306,
user='ai_cs_user',
password='Zuowei1216',
database='ai_cs',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor
)
cur = conn.cursor()
# 查昨晚18:00到今早的AI回复
cur.execute("""
SELECT customer_name, message, timestamp FROM chat_logs
WHERE timestamp >= '2026-03-05 18:00:00' AND timestamp <= '2026-03-06 09:00:00'
AND direction = 'out'
ORDER BY timestamp
""")
rows = cur.fetchall()
print(f"{len(rows)} 条AI回复检查乱码...")
for r in rows:
msg = r['message'] or ''
# 检查是否有乱码特征
has_code = any([
re.search(r'\[\]<\|', msg),
re.search(r'<\|[A-Za-z]+\|>', msg),
'Function' in msg,
'```' in msg,
re.search(r'\{["\']', msg), # JSON格式
re.search(r'\\n', msg), # 转义字符
])
if has_code:
print(f"\n[{r['timestamp']}] {r['customer_name']}:")
print(f" {msg[:150]}")
conn.close()
print("\n检查完成")