From c76f5dde80c03911fd37d769a6fc07953911a250 Mon Sep 17 00:00:00 2001 From: shuaikangzhou <863909694@qq.com> Date: Sat, 17 Feb 2024 22:21:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=8A=A8=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/log/exception_handling.py | 31 +++++++++++++++++++++++++++++++ app/person.py | 2 +- main.py | 6 ++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/log/exception_handling.py b/app/log/exception_handling.py index cef46c5..e3bacd0 100644 --- a/app/log/exception_handling.py +++ b/app/log/exception_handling.py @@ -2,6 +2,10 @@ import sqlite3 import sys import traceback +import requests + +from app.person import Me + class ExceptionHanding: def __init__(self, exc_type, exc_value, traceback_): @@ -40,3 +44,30 @@ def excepthook(exc_type, exc_value, traceback_): # 调用原始的 excepthook,以便程序正常退出 sys.__excepthook__(exc_type, exc_value, traceback_) + +def send_error_msg( message): + url = "http://api.lc044.love/error" + if not message: + return { + 'code': 201, + 'errmsg': '日志为空' + } + data = { + 'username': Me().wxid, + 'error': message + } + try: + response = requests.post(url, json=data) + if response.status_code == 200: + resp_info = response.json() + return resp_info + else: + return { + 'code': 503, + 'errmsg': '服务器错误' + } + except: + return { + 'code': 404, + 'errmsg': '客户端错误' + } diff --git a/app/person.py b/app/person.py index d5edeef..b813a79 100644 --- a/app/person.py +++ b/app/person.py @@ -59,7 +59,7 @@ class Me(Person): super().__init__() self.avatar = QPixmap(Icon.Default_avatar_path) self.avatar_path = ':/icons/icons/default_avatar.svg' - self.wxid = '' + self.wxid = 'wxid_00112233' self.wx_dir = '' self.name = '' self.mobile = '' diff --git a/main.py b/main.py index 2057b92..b6ab97e 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ import sys import time import traceback -from app.log.exception_handling import ExceptionHanding +from app.log.exception_handling import ExceptionHanding, send_error_msg from app.ui.Icon import Icon widget = None @@ -17,6 +17,8 @@ def excepthook(exc_type, exc_value, traceback_): error_message = ExceptionHanding(exc_type, exc_value, traceback_) txt = '您可添加QQ群发送log文件以便解决该问题' msg = f"Exception Type: {exc_type.__name__}\nException Value: {exc_value}\ndetails: {error_message}\n\n{txt}" + if SEND_LOG_FLAG: + send_error_msg(msg) logger.error(f'程序发生了错误:\n\n{msg}') # 创建一个 QMessageBox 对象 error_box = QMessageBox() @@ -49,7 +51,7 @@ from app.DataBase import close_db from app.log import logger from app.ui import mainview from app.ui.tool.pc_decrypt import pc_decrypt -from app.config import version +from app.config import version, SEND_LOG_FLAG ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("WeChatReport") QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)