代码拉取完成,页面将自动刷新
# -*- coding: utf-8 -*-
"""
@Tool : PyCharm
@User : 21407
@File : main.py
@Email: yypqcaa@163.com
@Date : 2023/2/26 21:47
@Desc :
"""
import sys
import shutil
import psutil
import traceback
from pathlib import Path
from loguru import logger
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWidgets import QApplication
from ui.main_ui import MainUi
def handleException(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
return sys.__excepthook__(exc_type, exc_value, exc_traceback)
exception = str("".join(traceback.format_exception(exc_type, exc_value, exc_traceback)))
dialog = QtWidgets.QDialog()
# close对其进行删除操作
dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)
msg = QtWidgets.QMessageBox(dialog)
msg.setIcon(QtWidgets.QMessageBox.Critical)
msg.setText(exception)
msg.setWindowTitle("系统异常提示")
msg.setDetailedText(exception)
msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
msg.exec_()
class MyTool:
def __init__(self):
from constant import LOG_PATH, EMAIL_CHECK_PATH, EMAIL_SEARCH_PATH, EXE_NAME, DRIVER_PATH, DATA_PATH, \
CONFIG_DEST_PATH, CONFIG_SOURCE_PATH, TEMPLATE_PATH, STATIC_PATH, EMAIL_SHOP_PATH, EMAIL_CNH_PATH
self.close_program(EXE_NAME)
for str_path in [LOG_PATH, EMAIL_CHECK_PATH, EMAIL_SEARCH_PATH, DATA_PATH, DRIVER_PATH,
CONFIG_DEST_PATH, TEMPLATE_PATH, EMAIL_SHOP_PATH, EMAIL_CNH_PATH]:
if not Path(str_path).is_dir():
Path(str_path).mkdir(exist_ok=True)
# 复制配置文件
for str_file in ['config.json', 'email.json']:
if not Path(CONFIG_DEST_PATH, str_file).exists():
shutil.copy(Path(CONFIG_SOURCE_PATH, str_file).__str__(), Path(CONFIG_DEST_PATH, str_file).__str__())
# 复制初始模板
if not Path(TEMPLATE_PATH, 'templates.html').exists():
shutil.copy(Path(STATIC_PATH, 'template', 'templates.html').__str__(),
Path(TEMPLATE_PATH, 'templates.html').__str__())
logger.add(Path(LOG_PATH).joinpath("log.log").__str__(), rotation="500MB", encoding="utf-8", enqueue=True, retention="10 days")
# 自定义异常
sys.excepthook = handleException
@staticmethod
def close_program(exec_name: str):
"""关闭软件"""
try:
lst_ps = [proc.name() for proc in psutil.process_iter() if proc.name() == exec_name]
if len(lst_ps) > 2:
sys.exit(0)
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
sys.exit(0)
if __name__ == '__main__':
obj_init = MyTool()
app = QApplication([])
obj_a = MainUi()
sys.exit(app.exec_())
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。