增加日志模块

This commit is contained in:
shuaikangzhou 2023-11-13 21:54:58 +08:00
parent 5ccf2292e1
commit 7b50f47332
10 changed files with 90 additions and 49 deletions

1
.gitignore vendored
View File

@ -11,4 +11,5 @@ app/data/image2
app/data/emoji
*.db
*.pyc
*.log
test*

View File

@ -4,9 +4,15 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="84e65474-7da9-466d-baf3-cc88dde3ffdd" name="变更" comment="main首次加载解密界面">
<change afterPath="$PROJECT_DIR$/doc/数据库介绍.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/readme.md" beforeDir="false" afterPath="$PROJECT_DIR$/readme.md" afterDir="false" />
<list default="true" id="84e65474-7da9-466d-baf3-cc88dde3ffdd" name="变更" comment="update readme">
<change afterPath="$PROJECT_DIR$/app/log/__init__.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/app/log/logger.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Ui/chat/chat.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/Ui/chat/chat.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Ui/contact/analysis/analysis.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/Ui/contact/analysis/analysis.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Ui/contact/analysis/charts.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/Ui/contact/analysis/charts.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/doc/获取个人文件/使用说明.md" beforeDir="false" afterPath="$PROJECT_DIR$/doc/获取个人文件/使用说明.md" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -72,7 +78,7 @@
<recent name="D:\Project\PythonProject\WeChatMsg\app\Ui" />
</key>
</component>
<component name="RunManager" selected="Python.decrypt_window">
<component name="RunManager" selected="Python.main">
<configuration name="decrypt" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="WeChatMsg" />
<option name="INTERPRETER_OPTIONS" value="" />
@ -201,11 +207,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.main" />
<item itemvalue="Python.decrypt_window" />
<item itemvalue="Python.decrypt" />
<item itemvalue="Python.get_wx_info" />
<item itemvalue="Python.micro_msg (1)" />
<item itemvalue="Python.main" />
</list>
</recent_temporary>
</component>
@ -221,13 +227,6 @@
<option name="presentableId" value="Default" />
<updated>1672848140146</updated>
</task>
<task id="LOCAL-00004" summary="update1">
<created>1673413541210</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1673413541210</updated>
</task>
<task id="LOCAL-00005" summary="update1">
<created>1674280781244</created>
<option name="number" value="00005" />
@ -564,7 +563,14 @@
<option name="project" value="LOCAL" />
<updated>1699797493106</updated>
</task>
<option name="localTasksCounter" value="53" />
<task id="LOCAL-00053" summary="update readme">
<created>1699797862964</created>
<option name="number" value="00053" />
<option name="presentableId" value="LOCAL-00053" />
<option name="project" value="LOCAL" />
<updated>1699797862964</updated>
</task>
<option name="localTasksCounter" value="54" />
<servers />
</component>
<component name="UnknownFeatures">
@ -614,7 +620,6 @@
<MESSAGE value="修复部分bug" />
<MESSAGE value="替换chat里的contact" />
<MESSAGE value="增加中文路径提示" />
<MESSAGE value="update readme" />
<MESSAGE value="用stackWidget重写contactUI" />
<MESSAGE value="修改联系人视图架构" />
<MESSAGE value="加快打开速度" />
@ -625,7 +630,8 @@
<MESSAGE value="增加导航按钮效果" />
<MESSAGE value="新增PC数据库解密" />
<MESSAGE value="main首次加载解密界面" />
<option name="LAST_COMMIT_MESSAGE" value="main首次加载解密界面" />
<MESSAGE value="update readme" />
<option name="LAST_COMMIT_MESSAGE" value="update readme" />
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
</component>

View File

@ -14,6 +14,7 @@ from docxcompose.composer import Composer
from app import person
from app.DataBase import data
from app.log import log
# import data
@ -64,6 +65,7 @@ class Output(QThread):
self.output_type = type_
self.total_num = 0
@log
def merge_docx(self, conRemark, n):
origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/{conRemark}"
all_file_path = []
@ -98,6 +100,7 @@ class Output(QThread):
self.okSignal.emit(1)
self.progressSignal.emit(self.i)
@log
def to_csv(self, conRemark, path):
origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/{conRemark}"
messages = data.get_all_message(self.ta_username)

View File

@ -8,6 +8,7 @@
@comment : 聊天窗口
"""
import time
import traceback
from typing import Dict
import xmltodict
@ -17,6 +18,7 @@ from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from app.Ui.MyComponents.Button_Contact import ContactUi
from app.log import logger, log
from .chatUi import *
from ...DataBase import data
from ...ImageBox.ui import MainDemo
@ -68,28 +70,6 @@ class ChatController(QWidget, Ui_Form):
self.message.setOpenExternalLinks(False)
# self.message.anchorClicked(self.hyperlink())
self.message.anchorClicked.connect(self.hyperlink)
# self.btn_sendMsg = QtWidgets.QPushButton(self.textEdit)
# self.btn_sendMsg.setGeometry(QtCore.QRect(1, 1, 121, 51))
# font = QtGui.QFont()
# font.setFamily("黑体")
# font.setPointSize(15)
# font.setBold(False)
# font.setWeight(50)
# self.btn_sendMsg.setFont(font)
# self.btn_sendMsg.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
# self.btn_sendMsg.setMouseTracking(False)
# self.btn_sendMsg.setAutoFillBackground(False)
# self.btn_sendMsg.setStyleSheet("QPushButton {background-color: #f0f0f0;\n"
# "padding: 10px;\n"
# "color:rgb(5,180,104);}\n"
# "QPushButton:hover{background-color: rgb(198,198,198)}\n"
# )
# self.btn_sendMsg.setIconSize(QtCore.QSize(40, 40))
# self.btn_sendMsg.setCheckable(False)
# self.btn_sendMsg.setAutoDefault(True)
# self.btn_sendMsg.setObjectName("btn_sendMsg")
# _translate = QtCore.QCoreApplication.translate
# self.btn_sendMsg.setText(_translate("Dialog", "发送"))
self.btn_sendMsg_2.setToolTip('按Enter键发送按Ctrl+Enter键换行')
def showChat(self):
@ -204,6 +184,7 @@ class ChatController(QWidget, Ui_Form):
self.last_msg_time = msg_time
self.message.insertHtml(html)
@log
def showMsg(self, message):
"""
显示聊天消息
@ -236,6 +217,7 @@ class ChatController(QWidget, Ui_Form):
self.pat_a_pat(content)
# self.message.moveCursor(self.message.textCursor().End)
@log
def pat_a_pat(self, content):
try:
pat_data = xmltodict.parse(content)
@ -262,6 +244,7 @@ class ChatController(QWidget, Ui_Form):
</table>''' % template
self.message.insertHtml(html)
@log
def show_recall_information(self, content):
html = '''
<table align="center" style="vertical-align: middle;">
@ -273,14 +256,15 @@ class ChatController(QWidget, Ui_Form):
</table>''' % content
self.message.insertHtml(html)
@log
def show_emoji(self, isSend, imagePath, content):
imgPath = data.get_emoji(imagePath)
print('emoji:', imgPath)
if not imgPath:
return False
try:
image = Image.open(imgPath)
except Exception as e:
logger.error(f"\nshow_emoji is error,here are details:\n{traceback.format_exc()}")
print(e)
return
imagePixmap = image.size # 宽高像素
@ -303,6 +287,7 @@ class ChatController(QWidget, Ui_Form):
self.chatroom_left(html, username=username, style=style)
self.left(html, style=style)
@log
def show_img(self, isSend, imgPath, content):
'THUMBNAIL_DIRPATH://th_29cd0f0ca87652943be9ede365aabeaa'
# imgPath = imgPath.split('th_')[1]
@ -325,6 +310,7 @@ class ChatController(QWidget, Ui_Form):
else:
self.left(html, style=style)
@log
def show_text(self, isSend, content):
if isSend:
html = '''

View File

@ -18,8 +18,6 @@ class AnalysisController(QWidget):
# self.setWindowFlag(Qt.FramelessWindowHint)
self.setStyleSheet('''QWidget{background-color:rgb(255, 255, 255);}''')
# self.setBackground()
# self.resize(400, 300)
self.center()
self.setAttribute(Qt.WA_AttributeCount)
self.label_01()

View File

@ -1,4 +1,5 @@
import os
import traceback
import jieba
import pandas as pd
@ -6,6 +7,7 @@ import xmltodict
from pyecharts import options as opts
from pyecharts.charts import Pie, WordCloud, Calendar, Bar, Line, Timeline, Grid
from app.log import logger, log
from ....DataBase import data
# from app.DataBase import data
@ -38,6 +40,7 @@ wordcloud_width = 780
wordcloud_height = 720
@log
def send_recv_rate(username):
send_num = data.send_nums(username)
recv_num = data.recv_nums(username)
@ -67,6 +70,7 @@ def send_recv_rate(username):
)
@log
def msg_type_rate(username):
type_data = data.msg_type_num(username)
type_data = sorted(type_data, key=lambda x: x[1], reverse=True)
@ -100,6 +104,7 @@ def msg_type_rate(username):
)
@log
def message_word_cloud(username):
text = data.get_text(username)
total_msg_len = len(text)
@ -132,6 +137,7 @@ def message_word_cloud(username):
)
@log
def calendar_chart(username):
msg_data = data.get_msg_by_days(username, year='2022')
if not msg_data:
@ -162,6 +168,7 @@ def calendar_chart(username):
)
@log
def month_num(username):
"""
每月聊天条数
@ -182,6 +189,7 @@ def month_num(username):
)
@log
def chat_session(username):
msg_data = data.get_msg_by_hour(username)
x_axis = list(map(lambda x: x[0], msg_data))
@ -219,6 +227,7 @@ def chat_session(username):
)
@log
def sport(username):
sports = data.get_sport()
ranks = []
@ -230,8 +239,8 @@ def sport(username):
rank_data = xmltodict.parse(content)
sub_data = rank_data['msg']['appmsg']['hardwareinfo']['messagenodeinfo']
# print(sub_data)
my_rank = sub_data['rankinfo']['rank']['rankdisplay']
my_steps = int(sub_data['rankinfo']['score']['scoredisplay'])
# my_rank = sub_data['rankinfo']['rank']['rankdisplay']
# my_steps = int(sub_data['rankinfo']['score']['scoredisplay'])
# print(f'rank: {my_rank},steps: {my_steps}')
rank_view = rank_data['msg']['appmsg']['hardwareinfo']['rankview']['rankinfolist']['rankinfo']
for userinfo in rank_view:
@ -243,6 +252,7 @@ def sport(username):
steps.append(steps_ta)
date.append(t)
except:
logger.error(f"\nsport is error,here are details:\n{traceback.format_exc()}\n")
continue
try:
# todo 可能没有运动信息
@ -349,6 +359,7 @@ def sport(username):
}
@log
def chat_start_endTime(username):
start_time = data.get_msg_start_time(username)
end_time = data.get_msg_end_time(username)
@ -431,11 +442,11 @@ setInterval(getRTime, 1000);
</body>
</html>
''' % (year, month + '-' + day, hour, minute, second, start_time)
print(year, month, day, hour, minute, second)
with open('./data/聊天统计/time.html', 'w', encoding='utf-8') as f:
f.write(html)
@log
def title(username):
conRemark = data.get_conRemark(username)
avatar = data.get_avator(username)
@ -519,7 +530,6 @@ font-size: 18px;
</body>
</html>
''' % (avatar, conRemark)
print('头像地址', avatar)
with open('./data/聊天统计/title.html', 'w', encoding='utf-8') as f:
f.write(html)

View File

@ -3,6 +3,7 @@ import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Line
from app.log import log
from ....DataBase import data
@ -18,6 +19,7 @@ def load_data(wxid):
import snownlp
@log
def emotion_analysis(wxid):
dates = []
emotions = []
@ -33,6 +35,7 @@ def emotion_analysis(wxid):
return dates, emotions
@log
def plot_emotion(wxid):
"""
画图

3
app/log/__init__.py Normal file
View File

@ -0,0 +1,3 @@
from .logger import log, logger
__all__ = ["logger", "log"]

33
app/log/logger.py Normal file
View File

@ -0,0 +1,33 @@
import logging
import os
import time
import traceback
from functools import wraps
filename = time.strftime("%Y-%m-%d", time.localtime(time.time()))
if not os.path.exists('./app/log/logs'):
os.mkdir('./app/log/logs')
logger = logging.getLogger('test')
logger.setLevel(level=logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')
file_handler = logging.FileHandler(f'./app/log/logs/{filename}-log.log')
file_handler.setLevel(level=logging.INFO)
file_handler.setFormatter(formatter)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
stream_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.addHandler(stream_handler)
def log(func):
@wraps(func)
def log_(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
logger.error(f"\n{func.__qualname__} is error,here are details:\n{traceback.format_exc()}")
return log_

View File

@ -3,16 +3,14 @@
对于模拟器中信息提取如果使用自带的Amaze复制到共享文件夹出现错误无法导入可以使用MT管理器
![image-20231113143254986](D:\code\project\WeChatMsg\doc\images\MT)
![image-20231113143254986](..\images\MT)
MT管理器打开界面如下图所示右边打开微信文件存储位置找到MicroMsg左边打开共享文件位置可以通过右边的电脑图案查看路径。
如图长按MicroMsg文件夹弹出弹窗点击复制->确认。
![image-20231111001821854](D:\code\project\WeChatMsg\doc\images\cv-opration)
![image-20231111001821854](..\images\cv-opration)
开始复制,稍等一会即可完成复制。
![image-20231111001132681](D:\code\project\WeChatMsg\doc\images\cv_process)
![image-20231111001132681](..\images\cv_process)