修改变量名

This commit is contained in:
shuaikangzhou 2023-12-30 19:26:24 +08:00
parent 3b75ba2455
commit c4ba4cc46c
14 changed files with 111 additions and 99 deletions

View File

@ -18,7 +18,7 @@ from docx.oxml.ns import qn
from .package_msg import PackageMsg
from ..DataBase import media_msg_db, hard_link_db, micro_msg_db, msg_db
from ..log import logger
from ..person import MePC
from ..person import Me
from ..util import path
from ..util.compress_content import parser_reply
from ..util.emoji import get_emoji_url
@ -270,22 +270,22 @@ class ChildThread(QThread):
if self.contact.is_chatroom:
avatar = message[12].smallHeadImgUrl
else:
avatar = MePC().smallHeadImgUrl if is_send else self.contact.smallHeadImgUrl
avatar = Me().smallHeadImgUrl if is_send else self.contact.smallHeadImgUrl
if is_absolute_path:
if self.contact.is_chatroom:
avatar = message[12].avatar_path
else:
avatar = MePC().avatar_path if is_send else self.contact.avatar_path
avatar = Me().avatar_path if is_send else self.contact.avatar_path
return avatar
def get_display_name(self, is_send, message) -> str:
if self.contact.is_chatroom:
if is_send:
display_name = MePC().name
display_name = Me().name
else:
display_name = message[12].remark
else:
display_name = MePC().name if is_send else self.contact.remark
display_name = Me().name if is_send else self.contact.remark
return escape_js_and_html(display_name)
def text(self, doc, message):
@ -332,9 +332,9 @@ class ChildThread(QThread):
if self.output_type == Output.HTML:
str_content = escape_js_and_html(str_content)
image_path = hard_link_db.get_image(str_content, BytesExtra, thumb=False)
if not os.path.exists(os.path.join(MePC().wx_dir, image_path)):
if not os.path.exists(os.path.join(Me().wx_dir, image_path)):
image_thumb_path = hard_link_db.get_image(str_content, BytesExtra, thumb=True)
if not os.path.exists(os.path.join(MePC().wx_dir, image_thumb_path)):
if not os.path.exists(os.path.join(Me().wx_dir, image_thumb_path)):
return
image_path = image_thumb_path
image_path = get_image_path(image_path, base_path=f'/data/聊天记录/{self.contact.remark}/image')
@ -351,9 +351,9 @@ class ChildThread(QThread):
run = content.paragraphs[0].add_run()
str_content = escape_js_and_html(str_content)
image_path = hard_link_db.get_image(str_content, BytesExtra, thumb=True)
if not os.path.exists(os.path.join(MePC().wx_dir, image_path)):
if not os.path.exists(os.path.join(Me().wx_dir, image_path)):
image_thumb_path = hard_link_db.get_image(str_content, BytesExtra, thumb=False)
if not os.path.exists(os.path.join(MePC().wx_dir, image_thumb_path)):
if not os.path.exists(os.path.join(Me().wx_dir, image_thumb_path)):
return
image_path = image_thumb_path
image_path = get_image_abs_path(image_path, base_path=f'/data/聊天记录/{self.contact.remark}/image')
@ -566,7 +566,7 @@ class ChildThread(QThread):
return
if video_path is None and image_path is None:
return
video_path = f'{MePC().wx_dir}/{video_path}'
video_path = f'{Me().wx_dir}/{video_path}'
if os.path.exists(video_path):
new_path = origin_docx_path + '/video/' + os.path.basename(video_path)
if not os.path.exists(new_path):
@ -741,9 +741,7 @@ class ChildThread(QThread):
messages = packagemsg.get_package_message_by_wxid(self.contact.wxid)
else:
messages = msg_db.get_messages(self.contact.wxid)
MePC().avatar.save(os.path.join(f"{origin_docx_path}/avatar/{MePC().wxid}.png"))
MePC().save_avatar(os.path.join(f"{origin_docx_path}/avatar/{MePC().wxid}.png"))
Me().save_avatar(os.path.join(f"{origin_docx_path}/avatar/{Me().wxid}.png"))
if self.contact.is_chatroom:
for message in messages:
if message[4]: # is_send
@ -884,9 +882,9 @@ class OutputImage(QThread):
timestamp = message[5]
try:
image_path = hard_link_db.get_image(str_content, BytesExtra, thumb=False)
if not os.path.exists(os.path.join(MePC().wx_dir, image_path)):
if not os.path.exists(os.path.join(Me().wx_dir, image_path)):
image_thumb_path = hard_link_db.get_image(str_content, BytesExtra, thumb=True)
if not os.path.exists(os.path.join(MePC().wx_dir, image_thumb_path)):
if not os.path.exists(os.path.join(Me().wx_dir, image_thumb_path)):
continue
image_path = image_thumb_path
image_path = get_image(image_path, base_path=f'/data/聊天记录/{self.contact.remark}/image')
@ -928,9 +926,9 @@ class OutputImageChild(QThread):
timestamp = message[5]
try:
image_path = hard_link_db.get_image(str_content, BytesExtra, thumb=False)
if not os.path.exists(os.path.join(MePC().wx_dir, image_path)):
if not os.path.exists(os.path.join(Me().wx_dir, image_path)):
image_thumb_path = hard_link_db.get_image(str_content, BytesExtra, thumb=True)
if not os.path.exists(os.path.join(MePC().wx_dir, image_thumb_path)):
if not os.path.exists(os.path.join(Me().wx_dir, image_thumb_path)):
continue
image_path = image_thumb_path
image_path = get_image(image_path, base_path=f'/data/聊天记录/{self.contact.remark}/image')

View File

@ -3,7 +3,7 @@ import threading
from app.DataBase import msg_db, micro_msg_db, misc_db
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
from app.util.protocbuf.roomdata_pb2 import ChatRoomData
from app.person import ContactPC, MePC, ContactDefault
from app.person import Contact, Me, ContactDefault
lock = threading.Lock()
@ -115,7 +115,7 @@ class PackageMsg:
for row in messages:
message = list(row)
if message[4] == 1: # 自己发送的就没必要解析了
message.append(MePC())
message.append(Me())
updated_messages.append(message)
continue
if message[10] is None: # BytesExtra是空的跳过
@ -146,7 +146,7 @@ class PackageMsg:
'NickName': contact_info_list[4],
'smallHeadImgUrl': contact_info_list[7]
}
contact = ContactPC(contact_info)
contact = Contact(contact_info)
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
contact.set_avatar(contact.smallHeadImgBLOG)
message.append(contact)

View File

@ -1,10 +1,11 @@
"""
定义各种联系人
"""
import os.path
import re
from typing import Dict
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from app.ui.Icon import Icon
@ -20,6 +21,11 @@ def singleton(cls):
class Person:
def __init__(self):
self.avatar_path = None
self.avatar = None
self.avatar_path_qt = Icon.Default_avatar_path
def set_avatar(self, img_bytes):
if not img_bytes:
self.avatar.load(Icon.Default_avatar_path)
@ -46,7 +52,7 @@ class Person:
@singleton
class MePC(Person):
class Me(Person):
def __init__(self):
self.avatar = QPixmap(Icon.Default_avatar_path)
self.avatar_path = ':/icons/icons/default_avatar.svg'
@ -57,7 +63,7 @@ class MePC(Person):
self.smallHeadImgUrl = ''
class ContactPC(Person):
class Contact(Person):
def __init__(self, contact_info: Dict):
self.wxid = contact_info.get('UserName')
self.remark = contact_info.get('Remark')
@ -87,7 +93,29 @@ class ContactDefault(Person):
self.is_chatroom = False
class Contacts:
def __init__(self):
self.contacts: Dict[str:Contact] = {}
def add(self, wxid, contact: Contact):
if wxid not in contact:
self.contacts[wxid] = contact
def get(self, wxid: str) -> Contact:
return self.contacts.get(wxid)
def remove(self, wxid: str):
return self.contacts.pop(wxid)
def save_avatar(self, avatar_dir: str = './data/avatar/'):
for wxid, contact in self.contacts.items():
avatar_path = os.path.join(avatar_dir, wxid + '.png')
if os.path.exists(avatar_path):
continue
contact.save_avatar(avatar_path)
if __name__ == '__main__':
p1 = MePC()
p2 = MePC()
p1 = Me()
p2 = Me()
print(p1 == p2)

View File

@ -5,7 +5,7 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout
from app.DataBase import msg_db, hard_link_db
from app.components.bubble_message import BubbleMessage, ChatWidget, Notice
from app.person import MePC
from app.person import Me
from app.util import get_abs_path
from app.util.emoji import get_emoji
@ -86,7 +86,7 @@ class ChatInfo(QWidget):
str_time = message[8]
# print(type_, type(type_))
is_send = message[4]
avatar = MePC().avatar if is_send else self.contact.avatar
avatar = Me().avatar if is_send else self.contact.avatar
timestamp = message[5]
BytesExtra = message[10]
if type_ == 1:

View File

@ -3,7 +3,7 @@ from PyQt5.QtWidgets import QWidget, QMessageBox, QAction, QLineEdit
from app.DataBase import micro_msg_db, misc_db, msg_db
from app.components import ContactQListWidgetItem, ScrollBar
from app.person import ContactPC
from app.person import Contact
from app.ui.Icon import Icon
from app.util import search
from .chatUi import Ui_Form
@ -126,7 +126,7 @@ class ChatWindow(QWidget, Ui_Form):
class ShowContactThread(QThread):
showSingal = pyqtSignal(ContactPC)
showSingal = pyqtSignal(Contact)
load_finish_signal = pyqtSignal(bool)
# heightSingal = pyqtSignal(int)
@ -145,7 +145,7 @@ class ShowContactThread(QThread):
'NickName': contact_info_list[4],
'smallHeadImgUrl': contact_info_list[7]
}
contact = ContactPC(contact_info)
contact = Contact(contact_info)
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
contact.set_avatar(contact.smallHeadImgBLOG)
self.showSingal.emit(contact)
@ -154,7 +154,7 @@ class ShowContactThread(QThread):
class ShowThread(QThread):
showSingal = pyqtSignal(ContactPC)
showSingal = pyqtSignal(Contact)
load_finish_signal = pyqtSignal(bool)
# heightSingal = pyqtSignal(int)

View File

@ -6,11 +6,14 @@ from app.DataBase.output_pc import Output
from app.ui.Icon import Icon
from .contactInfoUi import Ui_Form
from .userinfo import userinfo
from ...person import ContactPC, MePC
from ...person import Contact, Me
from .export_dialog import ExportDialog
class ContactInfo(QWidget, Ui_Form):
"""
显示联系人信息
"""
exitSignal = pyqtSignal()
urlSignal = pyqtSignal(QUrl)
@ -18,7 +21,7 @@ class ContactInfo(QWidget, Ui_Form):
def __init__(self, contact, parent=None):
super(ContactInfo, self).__init__(parent)
self.setupUi(self)
self.contact: ContactPC = contact
self.contact: Contact = contact
self.view_userinfo = userinfo.UserinfoController(self.contact)
self.btn_back.clicked.connect(self.back)
self.init_ui()
@ -61,14 +64,6 @@ class ContactInfo(QWidget, Ui_Form):
"马上就实现该功能"
)
return
self.stackedWidget.setCurrentWidget(self.view_analysis)
if 'room' in self.contact.wxid:
QMessageBox.warning(
self, '警告',
'暂不支持群组'
)
return
self.view_analysis.start()
def annual_report(self):
if 'room' in self.contact.wxid:
@ -78,7 +73,7 @@ class ContactInfo(QWidget, Ui_Form):
)
return
self.contact.save_avatar()
MePC().save_avatar()
Me().save_avatar()
self.report_thread = ReportThread(self.contact)
self.report_thread.okSignal.connect(lambda x: QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314")))
self.report_thread.start()
@ -96,15 +91,12 @@ class ContactInfo(QWidget, Ui_Form):
"马上就实现该功能"
)
return
self.stackedWidget.setCurrentWidget(self.view_emotion)
self.view_emotion.start()
def back(self):
"""
将userinfo界面设置为可见其他界面设置为不可见
"""
self.stackedWidget.setCurrentWidget(self.view_userinfo)
return
def output(self):
"""
@ -126,24 +118,6 @@ class ContactInfo(QWidget, Ui_Form):
dialog = ExportDialog(self.contact, title='选择导出的消息类型', file_type='txt', parent=self)
result = dialog.exec_() # 使用exec_()获取用户的操作结果
def hide_progress_bar(self, int):
reply = QMessageBox(self)
reply.setIcon(QMessageBox.Information)
reply.setWindowTitle('OK')
reply.setText(f"导出聊天记录成功\n在./data/目录下(跟exe文件在一起)")
reply.addButton("确认", QMessageBox.AcceptRole)
reply.addButton("取消", QMessageBox.RejectRole)
api = reply.exec_()
self.view_userinfo.progressBar.setVisible(False)
def output_progress(self, value):
self.view_userinfo.progressBar.setProperty('value', value)
def set_progressBar_range(self, value):
self.view_userinfo.progressBar.setVisible(True)
self.view_userinfo.progressBar.setRange(0, value)
class ReportThread(QThread):
okSignal = pyqtSignal(bool)

View File

@ -3,7 +3,7 @@ from PyQt5.QtWidgets import QWidget, QMessageBox, QAction, QLineEdit
from app.DataBase import micro_msg_db, misc_db
from app.components import ContactQListWidgetItem, ScrollBar
from app.person import ContactPC
from app.person import Contact
from app.ui.Icon import Icon
from .contactInfo import ContactInfo
from .contactUi import Ui_Form
@ -75,6 +75,10 @@ class ContactWindow(QWidget, Ui_Form):
self.stackedWidget.setCurrentIndex(0)
def show_contacts(self):
"""
创建一个子线程来获取联系人并通过信号传递联系人信息
@return:
"""
# return
if self.ok_flag:
return
@ -94,13 +98,22 @@ class ContactWindow(QWidget, Ui_Form):
self.ok_flag = True
def search_contact(self):
"""
搜索联系人
@return:
"""
keyword = self.lineEdit.text()
if keyword:
index = search.search_by_content(keyword, self.contacts)
self.listWidget.setCurrentRow(index)
self.stackedWidget.setCurrentIndex(index)
def show_contact(self, contact: ContactPC):
def show_contact(self, contact: Contact):
"""
显示联系人
@param contact:联系人对象
@return:
"""
self.contacts[0].append(contact.remark)
self.contacts[1].append(contact.nickName)
contact_item = ContactQListWidgetItem(contact.remark, contact.smallHeadImgUrl, contact.smallHeadImgBLOG)
@ -121,7 +134,7 @@ class ContactWindow(QWidget, Ui_Form):
class ShowContactThread(QThread):
showSingal = pyqtSignal(ContactPC)
showSingal = pyqtSignal(Contact)
load_finish_signal = pyqtSignal(bool)
# heightSingal = pyqtSignal(int)
@ -140,7 +153,7 @@ class ShowContactThread(QThread):
'NickName': contact_info_list[4],
'smallHeadImgUrl': contact_info_list[7]
}
contact = ContactPC(contact_info)
contact = Contact(contact_info)
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
contact.set_avatar(contact.smallHeadImgBLOG)
self.showSingal.emit(contact)
@ -149,7 +162,7 @@ class ShowContactThread(QThread):
class ShowThread(QThread):
showSingal = pyqtSignal(ContactPC)
showSingal = pyqtSignal(Contact)
load_finish_signal = pyqtSignal(bool)
# heightSingal = pyqtSignal(int)

View File

@ -24,7 +24,7 @@ from .contact import ContactWindow
from .tool.tool_window import ToolWindow
from ..DataBase.output_pc import Output
from ..components.QCursorGif import QCursorGif
from ..person import MePC
from ..person import Me
# 美化样式表
Stylesheet = """
@ -106,7 +106,7 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow,QCursorGif):
dic = json.loads(f.read())
wxid = dic.get('wxid')
if wxid:
me = MePC()
me = Me()
me.wxid = dic.get('wxid')
me.name = dic.get('name')
me.mobile = dic.get('mobile')
@ -191,7 +191,7 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow,QCursorGif):
self.avatar.loadFromData(img_bytes, format='jfif')
self.avatar.scaled(60, 60)
contact_info_list = micro_msg_db.get_contact_by_username(wxid)
me = MePC()
me = Me()
me.set_avatar(img_bytes)
me.smallHeadImgUrl = contact_info_list[7]
self.myavatar.setScaledContents(True)

View File

@ -6,7 +6,7 @@ import requests
from app.log import log, logger
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
from ..person import MePC
from ..person import Me
root_path = './data/files/'
if not os.path.exists('./data'):
@ -33,7 +33,7 @@ def get_file(bytes_extra, thumb=False, output_path=root_path) -> str:
if file_field.find('sec_msg_node') == -1:
file_original_path = file_field
file_name = os.path.basename(file_original_path)
if file_name != '' and file_name != MePC().wxid:
if file_name != '' and file_name != Me().wxid:
file_path = os.path.join(output_path, file_name)
if os.path.exists(file_path):
print('文件' + file_path + '已存在')
@ -43,13 +43,13 @@ def get_file(bytes_extra, thumb=False, output_path=root_path) -> str:
real_path = file_original_path
else: # 如果没找到再判断一次是否是迁移了目录
if file_original_path.find(r"FileStorage") != -1:
real_path = MePC().wx_dir + file_original_path[
real_path = Me().wx_dir + file_original_path[
file_original_path.find("FileStorage") - 1:]
else:
if file_original_path.find(MePC().wxid) != -1:
real_path = MePC().wx_dir + file_original_path.replace(MePC().wxid, '')
if file_original_path.find(Me().wxid) != -1:
real_path = Me().wx_dir + file_original_path.replace(Me().wxid, '')
else:
real_path = MePC().wx_dir + file_original_path
real_path = Me().wx_dir + file_original_path
if real_path != "":
if os.path.exists(real_path):
print('开始获取文件' + real_path)

View File

@ -1,6 +1,6 @@
import os
from app.person import MePC
from app.person import Me
# 图片字节头信息,
# [0][1]为jpg头信息
@ -110,7 +110,7 @@ def find_datfile(dir_path, out_path):
def get_image(path, base_path) -> str:
if path:
base_path = os.getcwd() + base_path
output_path = decode_dat(os.path.join(MePC().wx_dir, path), base_path)
output_path = decode_dat(os.path.join(Me().wx_dir, path), base_path)
relative_path = './image/' + os.path.basename(
output_path) if output_path else 'https://www.bing.com/images/search?view=detailV2&ccid=Zww6woP3&id=CCC91337C740656E800E51247E928ACD3052FECF&thid=OIP.Zww6woP3Em49TdSG_lnggAHaEK&mediaurl=https%3a%2f%2fmeekcitizen.files.wordpress.com%2f2018%2f09%2f404.jpg%3fw%3d656&exph=360&expw=640&q=404&simid=608040792714530493&FORM=IRPRST&ck=151E7337A86F1B9C5C5DB08B15B90809&selectedIndex=21&itb=0'
return relative_path
@ -121,7 +121,7 @@ def get_image(path, base_path) -> str:
def get_image_abs_path(path, base_path) -> str:
if path:
base_path = os.getcwd() + base_path
output_path = decode_dat(os.path.join(MePC().wx_dir, path), base_path)
output_path = decode_dat(os.path.join(Me().wx_dir, path), base_path)
return output_path
else:
return ':/icons/icons/404.png'
@ -130,7 +130,7 @@ def get_image_abs_path(path, base_path) -> str:
def get_image_path(path, base_path) -> str:
if path:
base_path = os.getcwd() + base_path
output_path = decode_dat_path(os.path.join(MePC().wx_dir, path), base_path)
output_path = decode_dat_path(os.path.join(Me().wx_dir, path), base_path)
relative_path = './image/' + os.path.basename(
output_path) if output_path else 'https://www.bing.com/images/search?view=detailV2&ccid=Zww6woP3&id=CCC91337C740656E800E51247E928ACD3052FECF&thid=OIP.Zww6woP3Em49TdSG_lnggAHaEK&mediaurl=https%3a%2f%2fmeekcitizen.files.wordpress.com%2f2018%2f09%2f404.jpg%3fw%3d656&exph=360&expw=640&q=404&simid=608040792714530493&FORM=IRPRST&ck=151E7337A86F1B9C5C5DB08B15B90809&selectedIndex=21&itb=0'
return relative_path
@ -139,8 +139,4 @@ def get_image_path(path, base_path) -> str:
if __name__ == "__main__":
path = "E:\86390\Documents\WeChat Files\wxid_27hqbq7vx5hf22\FileStorage\CustomEmotion\\71\\"
outpath = "D:\\test"
if not os.path.exists(outpath):
os.mkdir(outpath)
find_datfile(path, outpath)
pass

View File

@ -1,7 +1,7 @@
import os
import winreg
from app.person import MePC
from app.person import Me
from app.util import image
os.makedirs('./data/image', exist_ok=True)
@ -11,7 +11,7 @@ def get_abs_path(path, base_path="/data/image"):
# return os.path.join(os.getcwd(), 'app/data/icons/404.png')
if path:
base_path = os.getcwd() + base_path
output_path = image.decode_dat(os.path.join(MePC().wx_dir, path), base_path)
output_path = image.decode_dat(os.path.join(Me().wx_dir, path), base_path)
return output_path if output_path else ':/icons/icons/404.png'
else:
return ':/icons/icons/404.png'
@ -20,7 +20,7 @@ def get_abs_path(path, base_path="/data/image"):
def get_relative_path(path, base_path, type_='image'):
if path:
base_path = os.getcwd() + base_path
output_path = image.decode_dat(os.path.join(MePC().wx_dir, path), base_path)
output_path = image.decode_dat(os.path.join(Me().wx_dir, path), base_path)
relative_path = './image/' + os.path.basename(
output_path) if output_path else 'https://www.bing.com/images/search?view=detailV2&ccid=Zww6woP3&id=CCC91337C740656E800E51247E928ACD3052FECF&thid=OIP.Zww6woP3Em49TdSG_lnggAHaEK&mediaurl=https%3a%2f%2fmeekcitizen.files.wordpress.com%2f2018%2f09%2f404.jpg%3fw%3d656&exph=360&expw=640&q=404&simid=608040792714530493&FORM=IRPRST&ck=151E7337A86F1B9C5C5DB08B15B90809&selectedIndex=21&itb=0'
return relative_path

View File

@ -5,13 +5,13 @@ from flask import Flask, render_template, send_file
from app.DataBase import msg_db
from app.analysis import analysis
from app.person import ContactPC, MePC
from app.person import Contact, Me
from app.util.emoji import get_most_emoji
app = Flask(__name__)
wxid = ''
contact: ContactPC = None
contact: Contact = None
@app.route("/")
@ -29,9 +29,9 @@ def christmas():
first_time = '2023-01-01 00:00:00'
data = {
'ta_avatar_path': contact.avatar_path,
'my_avatar_path': MePC().avatar_path,
'my_avatar_path': Me().avatar_path,
'ta_nickname': contact.remark,
'my_nickname': MePC().name,
'my_nickname': Me().name,
'first_time': first_time,
}
wordcloud_cloud_data = analysis.wordcloud_christmas(contact.wxid)

BIN
doc/images/qq.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 503 KiB

View File

@ -292,8 +292,11 @@ python main.py
## 加群方式
关注官方公众号,回复:联系方式
1. 关注官方公众号,回复:联系方式
2. QQ扫码入群
后续更新将会在公众号同步发布
![](./doc/images/weixin.png)
<div>
<img src="./doc/images/weixin.png">
<img src="./doc/images/qq.jpg" height="200">
</div>