51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QTextEdit, QVBoxLayout, QDialog, QFileDialog, QMessageBox
|
|
import sqlite3
|
|
from datetime import datetime
|
|
import pandas as pd
|
|
import re
|
|
|
|
import logging
|
|
|
|
# 로거 인스턴스 가져오기
|
|
logger = logging.getLogger('default_logger')
|
|
class TextDialog(QDialog):
|
|
def __init__(self, conn, parent=None):
|
|
super(TextDialog, self).__init__(parent)
|
|
self.setWindowTitle("텍스트 입력")
|
|
self.setGeometry(100, 100, 400, 200)
|
|
|
|
self.textEdit = QTextEdit(self)
|
|
self.saveButton = QPushButton("저장", self)
|
|
self.saveButton.clicked.connect(self.save_data)
|
|
|
|
layout = QVBoxLayout()
|
|
layout.addWidget(self.textEdit)
|
|
layout.addWidget(self.saveButton)
|
|
self.setLayout(layout)
|
|
|
|
self.conn = conn
|
|
|
|
def save_data(self):
|
|
text = self.textEdit.toPlainText()
|
|
lines = text.split('\n')
|
|
keywords = []
|
|
categories = []
|
|
for line in lines:
|
|
# parts = line.split(' ') # 두 칸 띄어쓰기로 분리
|
|
# 두 칸 또는 세 칸 띄어쓰기로 분리
|
|
parts = re.split(r' {2,3}', line)
|
|
if len(parts) == 2:
|
|
keyword = parts[0].strip() # 양쪽 끝의 공백 제거
|
|
category = parts[1].strip() # 양쪽 끝의 공백 제거
|
|
keywords.append(keyword)
|
|
categories.append(category)
|
|
|
|
# pandas DataFrame을 사용하여 DB에 저장
|
|
df = pd.DataFrame({'keyword': keywords, 'base_category': categories})
|
|
# conn = sqlite3.connect(self.db_name)
|
|
df.to_sql('Keywords', self.conn, if_exists='append', index=False)
|
|
QMessageBox.information(self, "알림", "데이터가 DB에 저장되었습니다.")
|
|
self.accept()
|
|
|
|
def getDbName(self):
|
|
return self.db_name |