Skip to content

Commit

Permalink
增加日志模块
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed Nov 13, 2023
1 parent 5ccf229 commit 7b50f47
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ app/data/image2
app/data/emoji
*.db
*.pyc
*.log
test*
36 changes: 21 additions & 15 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/DataBase/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from app import person
from app.DataBase import data
from app.log import log


# import data
Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(self, Me: person.Me, ta_u, parent=None, type_=DOCX):
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 = []
Expand Down Expand Up @@ -98,6 +100,7 @@ def progress(self, value):
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)
Expand Down
32 changes: 9 additions & 23 deletions app/Ui/chat/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@comment : 聊天窗口
"""
import time
import traceback
from typing import Dict

import xmltodict
Expand All @@ -17,6 +18,7 @@
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
Expand Down Expand Up @@ -68,28 +70,6 @@ def initui(self):
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):
Expand Down Expand Up @@ -204,6 +184,7 @@ def check_time(self, msg_time):
self.last_msg_time = msg_time
self.message.insertHtml(html)

@log
def showMsg(self, message):
"""
显示聊天消息
Expand Down Expand Up @@ -236,6 +217,7 @@ def showMsg(self, message):
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)
Expand All @@ -262,6 +244,7 @@ def pat_a_pat(self, content):
</table>''' % template
self.message.insertHtml(html)

@log
def show_recall_information(self, content):
html = '''
<table align="center" style="vertical-align: middle;">
Expand All @@ -273,14 +256,15 @@ def show_recall_information(self, content):
</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 # 宽高像素
Expand All @@ -303,6 +287,7 @@ def show_emoji(self, isSend, imagePath, content):
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]
Expand All @@ -325,6 +310,7 @@ def show_img(self, isSend, imgPath, content):
else:
self.left(html, style=style)

@log
def show_text(self, isSend, content):
if isSend:
html = '''
Expand Down
2 changes: 0 additions & 2 deletions app/Ui/contact/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def __init__(self, username, parent=None):

# 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()
Expand Down
18 changes: 14 additions & 4 deletions app/Ui/contact/analysis/charts.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import traceback

import jieba
import pandas as pd
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
Expand Down Expand Up @@ -38,6 +40,7 @@
wordcloud_height = 720


@log
def send_recv_rate(username):
send_num = data.send_nums(username)
recv_num = data.recv_nums(username)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -162,6 +168,7 @@ def calendar_chart(username):
)


@log
def month_num(username):
"""
每月聊天条数
Expand All @@ -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))
Expand Down Expand Up @@ -219,6 +227,7 @@ def chat_session(username):
)


@log
def sport(username):
sports = data.get_sport()
ranks = []
Expand All @@ -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:
Expand All @@ -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 可能没有运动信息
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -431,11 +442,11 @@ def chat_start_endTime(username):
</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)
Expand Down Expand Up @@ -519,7 +530,6 @@ def title(username):
</body>
</html>
''' % (avatar, conRemark)
print('头像地址', avatar)
with open('./data/聊天统计/title.html', 'w', encoding='utf-8') as f:
f.write(html)

Expand Down
3 changes: 3 additions & 0 deletions app/Ui/contact/emotion/emotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pyecharts import options as opts
from pyecharts.charts import Line

from app.log import log
from ....DataBase import data


Expand All @@ -18,6 +19,7 @@ def load_data(wxid):
import snownlp


@log
def emotion_analysis(wxid):
dates = []
emotions = []
Expand All @@ -33,6 +35,7 @@ def emotion_analysis(wxid):
return dates, emotions


@log
def plot_emotion(wxid):
"""
画图
Expand Down
3 changes: 3 additions & 0 deletions app/log/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .logger import log, logger

__all__ = ["logger", "log"]
Loading

0 comments on commit 7b50f47

Please sign in to comment.