Commit 0a4eaa3d by 宋鹏博

1

parents
# 默认忽略的文件
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="selenium" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N803" />
<option value="N802" />
<option value="N806" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/wsmonitor_sql.iml" filepath="$PROJECT_DIR$/.idea/wsmonitor_sql.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
# mysql数据库
import pymysql
from config import host, user, database_pwd, database, port
class DButils:
__conn = None
__cursor = None
# 连接数据库
@classmethod
def get_conn(cls):
if cls.__conn is None:
cls.__conn = pymysql.connect(host=host, port=port, user=user, password=database_pwd, database=database,
charset="utf8")
return cls.__conn
# 创建游标方法
@classmethod
def get_cursor(cls):
if cls.__cursor is None:
cls.__cursor = cls.get_conn().cursor()
return cls.__cursor
# sql执行查询方法
@classmethod
def select_sql(cls, sql):
result = None
try:
cursor = cls.get_cursor()
cursor.execute(sql)
result = cursor.fetchall()
except Exception as e:
print(e)
finally:
cls.close_cursor()
cls.close_conn()
return result
# 数据库的增删改操作
@classmethod
def uid_sql(cls, sql):
try:
conn = cls.get_conn()
cursor = cls.get_cursor()
cursor.execute(sql)
conn.commit()
except Exception as e:
print(e)
cls.get_conn().rollback()
finally:
cls.close_cursor()
cls.close_conn()
# 关闭游标方法
@classmethod
def close_cursor(cls):
if cls.__cursor:
cls.__cursor.close()
cls.__cursor = None
# 关闭连接
@classmethod
def close_conn(cls):
if cls.__conn:
cls.__conn.close()
cls.__conn = None
import json
import requests
from common.DButils import DButils
from config import wechaturl, error_answer
# 发送微信消息
def error_message(text, url=wechaturl, mobile_list=16638842134):
data = {
"msgtype": "text",
"text": {
"content": text,
"mentioned_mobile_list": [mobile_list]
}
}
requests.post(url, json=data)
# 发送mkdown格式微信消息
def mk_error_message(error_editor, error_answer, message_id, url=wechaturl):
data = {
"msgtype": "markdown",
"markdown": {
"content": f"ws推送<font color=\"warning\">异常</font>,请相关同事注意。\n>问题编辑:<font color=\"comment\">{error_editor}</font>\n>消息id:<font color=\"comment\">{message_id}</font>\n>返回消息:<font color=\"comment\">{error_answer}</font> "
}
}
requests.post(url, json=data)
# 查询ws异常消息
def ws_error(minute, error_answer_list=error_answer):
print("开始")
data = DButils().select_sql(
f"select emp_id,content,id from aicaptain.message_record mr WHERE create_time > NOW() - INTERVAL {minute} minute "
f"and msg_type != 1 and inquiry_msg_meta_id !=0; ")
for i in range(len(data)):
for n in error_answer_list:
if n in data[i][1]:
json_data = json.loads(data[i][1])
content = json_data['msgContentList'][0]['content']
print(content)
editor = DButils().select_sql(
f"select name from aicaptain.job where id= (SELECT job_id FROM aicaptain.employee WHERE "
f" id= {data[i][0]} ); ")
mk_error_message(editor[0][0], content, data[i][2])
print("结束")
# 测试环境数据库
# host = "122.112.227.235"
# user = "userop"
# database_pwd = "0#ztXqUzECGen8E"
# database = "aireview"
# port = 3306
# 生产环境aireview数据库
# host = "192.168.8.234"
# user = "aireview110"
# database_pwd = "4yFSvSBc"
# database = "aireview"
# port = 3306
# 生产环境aicaption数据库
host = "192.168.8.234"
user = "aicaptain110"
database_pwd = "ABs4B79c"
database = "aicaptain"
port = 3306
# 微信机器人url
wechaturl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5a4fa3ba-9974-44d3-9c1e-2428f77f8087"
# 问题词
error_answer = ["无法回答此类问题,请换个话题吧。", "回复超时"]
from common.cutils import ws_error
ws_error(10)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment