新增导出联系人功能

This commit is contained in:
shuaikangzhou 2023-12-07 20:35:51 +08:00
parent 92d0314b7c
commit 206a41fda6
8 changed files with 318 additions and 301 deletions

View File

@ -6,6 +6,7 @@ labels: ''
assignees: '' assignees: ''
--- ---
**是否检查过issues没有相同问题**
**bug描述** **bug描述**
A clear and concise description of what the bug is. A clear and concise description of what the bug is.

View File

@ -104,7 +104,6 @@ class Msg:
lock.release() lock.release()
return result[0] return result[0]
def get_message_by_num(self, username_, local_id): def get_message_by_num(self, username_, local_id):
sql = ''' sql = '''
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime
@ -227,7 +226,6 @@ class Msg:
# result.sort(key=lambda x: x[5]) # result.sort(key=lambda x: x[5])
return result return result
def get_first_time_of_message(self, username_): def get_first_time_of_message(self, username_):
if not self.open_flag: if not self.open_flag:
return None return None

View File

@ -3,8 +3,9 @@ import html
import os import os
from PyQt5.QtCore import pyqtSignal, QThread from PyQt5.QtCore import pyqtSignal, QThread
from PyQt5.QtWidgets import QFileDialog
from . import msg_db from . import msg_db, micro_msg_db
from .package_msg import PackageMsg from .package_msg import PackageMsg
from ..DataBase import hard_link_db from ..DataBase import hard_link_db
from ..person_pc import MePC from ..person_pc import MePC
@ -52,6 +53,7 @@ class Output(QThread):
DOCX = 1 DOCX = 1
HTML = 2 HTML = 2
CSV_ALL = 3 CSV_ALL = 3
CONTACT_CSV = 4
def __init__(self, contact, parent=None, type_=DOCX): def __init__(self, contact, parent=None, type_=DOCX):
super().__init__(parent) super().__init__(parent)
@ -71,12 +73,15 @@ class Output(QThread):
def to_csv_all(self): def to_csv_all(self):
origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/" origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/"
os.makedirs(origin_docx_path, exist_ok=True) os.makedirs(origin_docx_path, exist_ok=True)
filename = f"{os.path.abspath('.')}/data/聊天记录/messages.csv" filename = QFileDialog.getSaveFileName(None, "save file", os.path.join(os.getcwd(),'messages.csv'), "csv files (*.csv);;all files(*.*)")
if not filename:
return
filename = filename[0]
# columns = ["用户名", "消息内容", "发送时间", "发送状态", "消息类型", "isSend", "msgId"] # columns = ["用户名", "消息内容", "发送时间", "发送状态", "消息类型", "isSend", "msgId"]
columns = ['localId', 'TalkerId', 'Type', 'SubType', columns = ['localId', 'TalkerId', 'Type', 'SubType',
'IsSender', 'CreateTime', 'Status', 'StrContent', 'IsSender', 'CreateTime', 'Status', 'StrContent',
'StrTime', 'Remark', 'NickName', 'Sender'] 'StrTime', 'Remark', 'NickName', 'Sender']
# messages = msg_db.get_messages_all()
packagemsg = PackageMsg() packagemsg = PackageMsg()
messages = packagemsg.get_package_message_all() messages = packagemsg.get_package_message_all()
# 写入CSV文件 # 写入CSV文件
@ -87,11 +92,29 @@ class Output(QThread):
writer.writerows(messages) writer.writerows(messages)
self.okSignal.emit(1) self.okSignal.emit(1)
def contact_to_csv(self):
filename = QFileDialog.getSaveFileName(None, "save file", os.path.join(os.getcwd(),'contacts.csv'), "csv files (*.csv);;all files(*.*)")
if not filename:
return
filename = filename[0]
# columns = ["用户名", "消息内容", "发送时间", "发送状态", "消息类型", "isSend", "msgId"]
columns = ['UserName','Alias', 'Type', 'Remark', 'NickName', 'PYInitial', 'RemarkPYInitial', 'smallHeadImgUrl', 'bigHeadImgUrl']
contacts = micro_msg_db.get_contact()
# 写入CSV文件
with open(filename, mode='w', newline='', encoding='utf-8') as file:
writer = csv.writer(file)
writer.writerow(columns)
# 写入数据
writer.writerows(contacts)
self.okSignal.emit(1)
def run(self): def run(self):
if self.output_type == self.DOCX: if self.output_type == self.DOCX:
return return
elif self.output_type == self.CSV_ALL: elif self.output_type == self.CSV_ALL:
self.to_csv_all() self.to_csv_all()
elif self.output_type == self.CONTACT_CSV:
self.contact_to_csv()
else: else:
self.Child = ChildThread(self.contact, type_=self.output_type) self.Child = ChildThread(self.contact, type_=self.output_type)
self.Child.progressSignal.connect(self.progress) self.Child.progressSignal.connect(self.progress)

View File

@ -6,10 +6,8 @@ import sys
sys.path.append('.') sys.path.append('.')
from app.DataBase import msg_db, MsgType from app.DataBase import msg_db, MsgType
from app.person_pc import ContactPC
import jieba
from pyecharts import options as opts from pyecharts import options as opts
from pyecharts.charts import Pie, WordCloud, Calendar, Bar, Line, Timeline, Grid from pyecharts.charts import WordCloud, Calendar, Bar
from app.resources import resource_rc from app.resources import resource_rc
var = resource_rc.qt_resource_name var = resource_rc.qt_resource_name

View File

@ -102,6 +102,8 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow):
self.menu_output.setIcon(Icon.Output) self.menu_output.setIcon(Icon.Output)
self.action_output_CSV.setIcon(Icon.ToCSV) self.action_output_CSV.setIcon(Icon.ToCSV)
self.action_output_CSV.triggered.connect(self.output) self.action_output_CSV.triggered.connect(self.output)
self.action_output_contacts.setIcon(Icon.Output)
self.action_output_contacts.triggered.connect(self.output)
self.action_desc.setIcon(Icon.Help_Icon) self.action_desc.setIcon(Icon.Help_Icon)
self.action_help_contact.triggered.connect( self.action_help_contact.triggered.connect(
lambda: QDesktopServices.openUrl(QUrl("https://blog.lc044.love/post/5"))) lambda: QDesktopServices.openUrl(QUrl("https://blog.lc044.love/post/5")))
@ -192,7 +194,12 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow):
if self.sender() == self.action_output_CSV: if self.sender() == self.action_output_CSV:
self.outputThread = Output(None, type_=Output.CSV_ALL) self.outputThread = Output(None, type_=Output.CSV_ALL)
self.outputThread.okSignal.connect( self.outputThread.okSignal.connect(
lambda x: self.message('聊天记录导出成功\n./data/聊天记录/messages.csv')) lambda x: self.message('聊天记录导出成功'))
self.outputThread.start()
elif self.sender() == self.action_output_contacts:
self.outputThread = Output(None, type_=Output.CONTACT_CSV)
self.outputThread.okSignal.connect(
lambda x: self.message('联系人导出成功'))
self.outputThread.start() self.outputThread.start()
def message(self, msg): def message(self, msg):

View File

@ -124,12 +124,15 @@ class Ui_MainWindow(object):
self.action_help_contact.setObjectName("action_help_contact") self.action_help_contact.setObjectName("action_help_contact")
self.action_output_CSV = QtWidgets.QAction(MainWindow) self.action_output_CSV = QtWidgets.QAction(MainWindow)
self.action_output_CSV.setObjectName("action_output_CSV") self.action_output_CSV.setObjectName("action_output_CSV")
self.action_output_contacts = QtWidgets.QAction(MainWindow)
self.action_output_contacts.setObjectName("action_output_contacts")
self.menu_F.addSeparator() self.menu_F.addSeparator()
self.menu_F.addSeparator() self.menu_F.addSeparator()
self.menu_F.addAction(self.action_3) self.menu_F.addAction(self.action_3)
self.menu_F.addAction(self.action_4) self.menu_F.addAction(self.action_4)
self.menu_output.addAction(self.action_output_CSV) self.menu_output.addAction(self.action_output_CSV)
self.menu_data.addAction(self.menu_output.menuAction()) self.menu_data.addAction(self.menu_output.menuAction())
self.menu_data.addAction(self.action_output_contacts)
self.menu_2.addAction(self.action_help_decrypt) self.menu_2.addAction(self.action_help_decrypt)
self.menu_2.addAction(self.action_help_chat) self.menu_2.addAction(self.action_help_chat)
self.menu_2.addAction(self.action_help_contact) self.menu_2.addAction(self.action_help_contact)
@ -173,3 +176,4 @@ class Ui_MainWindow(object):
self.action_help_chat.setText(_translate("MainWindow", "聊天相关")) self.action_help_chat.setText(_translate("MainWindow", "聊天相关"))
self.action_help_contact.setText(_translate("MainWindow", "好友相关")) self.action_help_contact.setText(_translate("MainWindow", "好友相关"))
self.action_output_CSV.setText(_translate("MainWindow", "CSV")) self.action_output_CSV.setText(_translate("MainWindow", "CSV"))
self.action_output_contacts.setText(_translate("MainWindow", "导出联系人"))

View File

@ -199,6 +199,7 @@
<addaction name="action_output_CSV"/> <addaction name="action_output_CSV"/>
</widget> </widget>
<addaction name="menu_output"/> <addaction name="menu_output"/>
<addaction name="action_output_contacts"/>
</widget> </widget>
<widget class="QMenu" name="menu_2"> <widget class="QMenu" name="menu_2">
<property name="title"> <property name="title">
@ -266,6 +267,11 @@
<string>CSV</string> <string>CSV</string>
</property> </property>
</action> </action>
<action name="action_output_contacts">
<property name="text">
<string>导出联系人</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -1,11 +1,8 @@
import json
import os import os
import sys import sys
from flask import Flask, render_template, send_file from flask import Flask, render_template, send_file
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.globals import ThemeType
from app.DataBase import msg_db from app.DataBase import msg_db
from app.analysis import analysis from app.analysis import analysis
@ -19,25 +16,8 @@ contact: ContactPC = None
@app.route("/") @app.route("/")
def index(): def index():
# 创建一个简单的柱状图
bar = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
.add_xaxis(["A", "B", "C", "D", "E"])
.add_yaxis("Series", [5, 20, 36, 10, 75])
.set_global_opts(title_opts=opts.TitleOpts(title="Flask and Pyecharts Interaction"))
)
# 将图表转换成 HTML
chart_html = bar.render_embed()
# 渲染模板,并传递图表的 HTML 到模板中 # 渲染模板,并传递图表的 HTML 到模板中
return render_template("index.html", chart_html=chart_html) return render_template("index.html")
@app.route("/index")
def index0():
return render_template("index1.html")
@app.route('/home') @app.route('/home')
def home(): def home():