Skip to content

Commit

Permalink
Merge pull request LC044#12 from LC044/dev_zsk
Browse files Browse the repository at this point in the history
Dev zsk
  • Loading branch information
LC044 authored Nov 16, 2023
2 parents a126658 + 9c7cb67 commit d8639ed
Show file tree
Hide file tree
Showing 49 changed files with 3,255 additions and 461 deletions.
219 changes: 125 additions & 94 deletions .idea/workspace.xml

Large diffs are not rendered by default.

36 changes: 30 additions & 6 deletions app/DataBase/micro_msg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import os.path
import sqlite3
from pprint import pprint

DB = sqlite3.connect("./de_MicroMsg.db", check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()
DB = None
cursor = None
micromsg_path = "./app/Database/Msg/MicroMsg.db"
if os.path.exists(micromsg_path):
DB = sqlite3.connect(micromsg_path, check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()


def init_database():
global DB
global cursor
if not DB:
if os.path.exists(micromsg_path):
DB = sqlite3.connect(micromsg_path, check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()


def is_database_exist():
return os.path.exists(micromsg_path)


def get_contact():
Expand All @@ -14,10 +32,16 @@ def get_contact():
'''
cursor.execute(sql)
result = cursor.fetchall()
pprint(result)
print(len(result))
# pprint(result)
# print(len(result))
return result


def close():
global DB
if DB:
DB.close()


if __name__ == '__main__':
get_contact()
29 changes: 29 additions & 0 deletions app/DataBase/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os.path
import sqlite3

DB = None
cursor = None
misc_path = "./app/Database/Msg/Misc.db"
# misc_path = './Msg/Misc.db'
if os.path.exists(misc_path):
DB = sqlite3.connect(misc_path, check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()


def get_avatar_buffer(userName):
sql = '''
select smallHeadBuf
from ContactHeadImg1
where usrName=?;
'''
cursor.execute(sql, [userName])
result = cursor.fetchall()
# print(result[0][0])
if result:
return result[0][0]
return None


if __name__ == '__main__':
get_avatar_buffer('wxid_al2oan01b6fn11')
71 changes: 71 additions & 0 deletions app/DataBase/msg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import os.path
import re
import sqlite3

DB = []
cursor = []
msg_root_path = "./app/Database/Msg/"
# misc_path = './Msg/Misc.db'
if os.path.exists(msg_root_path):
for root, dirs, files in os.walk(msg_root_path):
for file in files:
if re.match('^MSG[0-9]+\.db$', file):
# print('ok', file)
msg_path = os.path.join(msg_root_path, file)
DB0 = sqlite3.connect(msg_path, check_same_thread=False)
# '''创建游标'''
cursor0 = DB0.cursor()
DB.append(DB0)
cursor.append(cursor0)


def init_database():
global DB
global cursor
if not DB:
if os.path.exists(msg_root_path):
for root, dirs, files in os.walk(msg_root_path):
for file in files:
# print(file)
if re.match('^MSG[0-9]+\.db$', file):
print('ok', file)
msg_path = os.path.join(msg_root_path, file)
DB0 = sqlite3.connect(msg_path, check_same_thread=False)
# '''创建游标'''
cursor0 = DB0.cursor()
DB.append(DB0)
cursor.append(cursor0)


def get_messages(username_):
sql = '''
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime
from MSG
where StrTalker=?
order by CreateTime
'''
result = []
for cur in cursor:
cur.execute(sql, [username_])
result_ = cur.fetchall()
# print(len(result))
result += result_
result.sort(key=lambda x: x[5])
return result


def close():
for db in DB:
db.close()


if __name__ == '__main__':
from pprint import pprint

msg_root_path = './Msg/'
init_database()

username = 'wxid_0o18ef858vnu22'
result = get_messages(username)
pprint(result)
pprint(len(result))
56 changes: 56 additions & 0 deletions app/DataBase/output_pc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os

import pandas as pd
from PyQt5.QtCore import pyqtSignal, QThread

from . import msg
from ..log import log


class Output(QThread):
"""
发送信息线程
"""
progressSignal = pyqtSignal(int)
rangeSignal = pyqtSignal(int)
okSignal = pyqtSignal(int)
i = 1
CSV = 0
DOCX = 1
HTML = 2

def __init__(self, contact, parent=None, type_=DOCX):
super().__init__(parent)
self.sec = 2 # 默认1000秒
self.contact = contact
self.ta_username = contact.wxid
self.msg_id = 0
self.output_type = type_
self.total_num = 0
self.num = 0

@log
def to_csv(self, conRemark, path):
origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}"
if not os.path.exists(origin_docx_path):
os.mkdir(origin_docx_path)
filename = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}/{self.contact.remark}.csv"
# columns = ["用户名", "消息内容", "发送时间", "发送状态", "消息类型", "isSend", "msgId"]
columns = ['localId', 'TalkerId', 'Type', 'SubType',
'IsSender', 'CreateTime', 'Status', 'StrContent',
'StrTime']
messages = msg.get_messages(self.contact.wxid)
# print()
df = pd.DataFrame(
data=messages,
columns=columns,
)
df.to_csv(filename, encoding='utf-8')
self.okSignal.emit('ok')

def run(self):
if self.output_type == self.DOCX:
return
elif self.output_type == self.CSV:
# print("线程导出csv")
self.to_csv(self.ta_username, "path")
Empty file removed app/Ui/MyComponents/__init__.py
Empty file.
3 changes: 1 addition & 2 deletions app/Ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
# 文件__init__.py
# from login import login
from app.Ui.decrypt import decrypt
from app.Ui.pc_decrypt import pc_decrypt

__all__ = ["decrypt", 'mainview', 'chat', 'pc_decrypt']
__all__ = ["decrypt", 'mainview', 'chat']
2 changes: 1 addition & 1 deletion app/Ui/chat/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

from app.Ui.MyComponents.Button_Contact import ContactUi
from app.components.Button_Contact import ContactUi
from app.log import logger, log
from .chatUi import *
from ...DataBase import data
Expand Down
2 changes: 1 addition & 1 deletion app/Ui/contact/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

import app.Ui.MyComponents.Button_Contact as MyLabel
import app.components.Button_Contact as MyLabel
from app import person
from app.DataBase import data
from app.Ui.contact.contactInfo import ContactInfo
Expand Down
1 change: 1 addition & 0 deletions app/Ui/contact/emotion/emotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def emotion_analysis(wxid):
emotions.append(s / len(messages))
emotions = np.array(emotions)
emotions = np.around(emotions, 3) * 100
emotions = np.around(emotions, 1)
return dates, emotions


Expand Down
6 changes: 5 additions & 1 deletion app/Ui/decrypt/decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def get_xml(self):
def get_db(self):
self.db_path, _ = QFileDialog.getOpenFileName(self, 'Open file', r'..', "Database files (*.db)")
if self.db_path:
if self.db_path.isascii():
if ' ' in self.db_path:
self.label_db.setText('数据库未就绪')
QMessageBox.critical(self, "错误", "db文件路径请不要带有空格\n可以放在D:\\\\data 目录下")
self.db_path = ''
elif self.db_path.isascii():
self.label_db.setText('数据库已就绪')
return self.db_path
else:
Expand Down
17 changes: 6 additions & 11 deletions app/Ui/mainview.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

from app import person, config
from app.DataBase import *
from app import config
from app.DataBase import data
from app.Ui import mainwindow
from app.Ui.Icon import Icon
from app.Ui.MyComponents.prompt_bar import PromptBar
from app.Ui.chat import chat
from app.Ui.contact import contact
from app.components.prompt_bar import PromptBar
from app.person import Me


class MainWinController(QMainWindow, mainwindow.Ui_MainWindow):
Expand All @@ -28,9 +29,9 @@ def __init__(self, username, parent=None):
super(MainWinController, self).__init__(parent)
self.setupUi(self)
self.setWindowIcon(Icon.MainWindow_Icon)
self.Me = person.Me(data.get_myinfo())
self.setAttribute(Qt.WA_AttributeCount)

self.setAttribute(Qt.WA_AttributeCount)
self.Me = Me(data.get_myinfo())
self.chatView = chat.ChatController(self.Me, parent=None)
self.lay = QHBoxLayout()
self.page_chat.setLayout(self.lay)
Expand Down Expand Up @@ -60,12 +61,6 @@ def __init__(self, username, parent=None):
self.statusbar.setVisible(False)
self.prompt_bar = PromptBar(self)
self.chat_view()
# self.state_lable = QLabel(self)
# self.state_lable.raise_()
# pixmap = QPixmap('./app/data/icons/default_avatar.svg').scaled(32, 32) # 按指定路径找到图片
# self.state_lable.setPixmap(pixmap)
# self.state_lable.setText("T")
# 创建右键菜单函数

def init_ui(self):
# self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
Expand Down
Empty file removed app/Ui/pc_decrypt/__init__.py
Empty file.
Loading

0 comments on commit d8639ed

Please sign in to comment.