Я создаю приложение, которое загружает MSG-файл outlook и сохраняет данные в теле сообщения в виде файла слова.Теперь мой вопрос состоит из двух частей: 1. Где в моем коде я могу извлечь данные в теле MSG-файла?2. Как я могу создать другую кнопку просмотра, которая сохраняет данные в теле MSG-файла в текстовом файле в другом месте.
import os
import sys
from PyQt5.QtGui import QPixmap,QStandardItemModel, QStandardItem
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QMainWindow, QLabel, QLineEdit, QCheckBox,
QComboBox, QMessageBox, QRadioButton, QButtonGroup, QTextEdit,
QProgressBar
from PyQt5.QtWidgets import QPushButton, QFileDialog,
QTableWidget,QTableWidgetItem, QWidget, QTableView, QAbstractItemView,
QToolTip, QApplication
from PyQt5.QtCore import QSize, QModelIndex, QItemSelection,
QItemSelectionModel, QBasicTimer, QThread, pyqtSignal, Qt
import win32com.client
import pandas as pd
import pdb
class OutlookThread(QThread):
signal = pyqtSignal('PyQt_PyObject')
def __init__(self, path_to_outlook):
QThread.__init__(self)
self.path_to_outlook = path_to_outlook
def run(self):
self.outlookpath
=win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
self.signal.emit(self.outlookpath)
class SetPathWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(700, 300))
self.setWindowTitle("Data Extraction From Email")
self.label = QLabel(self)
self.step1label = QLabel(self)
self.step1label.setText("Load the .msg file")
self.step1label.setStyleSheet('color: grey;font-weight: bold')
self.step1label.adjustSize()
self.step1label.move(50, 30)
self.line1 = self.create_fields_empty(50, 70, 480, 30)
self.line1.setPlaceholderText("Add the path of msg file...")
button1 = self.push_button('Browse', 550, 70, 100, 32)
button1.clicked.connect(self.get_outlook_file_path)
button5 = self.push_button('Next >>', 300, 150, 100, 32)
button5.clicked.connect(self.clicked)
def resource_path(self, relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def OutlookOpened(self, outlook_path):
QApplication.restoreOverrideCursor()
self.close()
def create_fields_text(self, x, y, text):
self.nameLabel = QLabel(self)
self.nameLabel.setText(text)
self.nameLabel.adjustSize()
self.nameLabel.move(x, y)
def create_fields_empty(self, x, y, len, width):
self.line = QLineEdit(self)
self.line.move(x, y)
self.line.resize(len, width)
return self.line
def push_button(self, name, x, y, len, width):
pybutton = QPushButton(name, self)
pybutton.move(x, y)
pybutton.resize(len, width)
pybutton.setStyleSheet(
"QPushButton { background-color: grey;color: white;font-weight: bold; border-radius: 5px}"
"QPushButton:pressed { background-color: grey ;color: black;font-weight: bold; border-radius: 5px}"
)
return pybutton
def get_outlook_file_path(self):
self.file1 = QFileDialog.getOpenFileName(self, "*.msg")
print('1',type(self.file1),self.file1)
self.line1.setText(self.file1[0])
print('2',type(self.file1[0]),self.file1[0])
self.outlook_thread = OutlookThread(self.file1[0])
print('3',type(self.outlook_thread),self.outlook_thread)
pdb.set_trace()
self.outlook_thread.signal.connect(self.OutlookOpened)
def clicked(self):
if self.line1.text() == '':
QMessageBox().warning(self, "Msg file path not found!", "Please select a .msg outlook file", QMessageBox.Ok)
else:
QApplication.setOverrideCursor(Qt.WaitCursor)
self.outlook_thread.start()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = SetPathWindow()
mainWin.show()
sys.exit(app.exec_())
Я не добавил функцию для преобразования тела сообщения Outlook вслово еще.Мне просто нужно знать, где данные после чтения файла.Вы можете просто напечатать информацию в теле сообщения, используя функцию.