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

24 lines
738 B
Python

import pymysql
import sys
try:
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
)
with conn.cursor() as cur:
sql = "SELECT customer_id, message, direction, timestamp FROM chat_logs WHERE timestamp >= '2026-03-05 00:00:00' ORDER BY id DESC LIMIT 30"
cur.execute(sql)
rows = cur.fetchall()
for r in rows:
dir_tag = "" if r["direction"] == "out" else ""
print(f"[{r['timestamp']}] {dir_tag} ({r['customer_id']}): {r['message']}")
finally:
if 'conn' in locals():
conn.close()