This commit is contained in:
parent
53071e4533
commit
0515ccc524
2
setup.py
2
setup.py
|
|
@ -17,7 +17,7 @@ if sys.platform == "win32":
|
|||
|
||||
setup(
|
||||
name="taomanXLS",
|
||||
version="1.1",
|
||||
version="1.2",
|
||||
description="Taoman_to_PercentyXLS",
|
||||
options={"build_exe": build_exe_options},
|
||||
executables=[Executable("taomanXLS.py", base=base, icon="taomanXLS.ico")]
|
||||
|
|
|
|||
96
taomanXLS.py
96
taomanXLS.py
|
|
@ -5,17 +5,25 @@ import random
|
|||
import configparser
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel,
|
||||
QFileDialog, QRadioButton, QTextEdit, QMessageBox, QLineEdit, QCheckBox
|
||||
QFileDialog, QRadioButton, QTextEdit, QMessageBox, QLineEdit, QCheckBox,
|
||||
QSpinBox
|
||||
)
|
||||
from PyQt5.QtCore import Qt, QThread, pyqtSignal
|
||||
import xlwings as xw
|
||||
import traceback
|
||||
|
||||
|
||||
class CommaSpinBox(QSpinBox):
|
||||
def textFromValue(self, value):
|
||||
return f"{value:,}" # 숫자에 콤마 추가
|
||||
|
||||
def valueFromText(self, text):
|
||||
return int(text.replace(",", "")) # 콤마 제거하고 숫자 변환
|
||||
|
||||
|
||||
class ExportThread(QThread):
|
||||
log_signal = pyqtSignal(str)
|
||||
finished_signal = pyqtSignal()
|
||||
|
||||
def __init__(self, data, export_format, output_folder, original_file_name, exclude_words, ban_words, shuffle_title):
|
||||
def __init__(self, data, export_format, output_folder, original_file_name, exclude_words, ban_words, shuffle_title, price_limit_enabled, price_limit):
|
||||
super().__init__()
|
||||
self.data = data
|
||||
self.export_format = export_format
|
||||
|
|
@ -24,9 +32,18 @@ class ExportThread(QThread):
|
|||
self.exclude_words = exclude_words
|
||||
self.ban_words = ban_words
|
||||
self.shuffle_title = shuffle_title
|
||||
self.price_limit_enabled = price_limit_enabled
|
||||
self.price_limit = price_limit
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
# 타오바오URL이 비어있는 데이터 제외
|
||||
self.data = self.data[self.data['타오바오URL'].notna() & self.data['타오바오URL'].str.strip().astype(bool)]
|
||||
|
||||
# 가격 제한 적용
|
||||
if self.price_limit_enabled:
|
||||
self.data = self.data[self.data['가격'] >= self.price_limit]
|
||||
|
||||
chunk_size = 50
|
||||
for i in range(0, len(self.data), chunk_size):
|
||||
chunk = self.data.iloc[i:i+chunk_size].copy()
|
||||
|
|
@ -77,9 +94,27 @@ class ExportThread(QThread):
|
|||
template_wb.close()
|
||||
|
||||
elif self.export_format == "헤이셀러":
|
||||
# Implement 헤이셀러 export format if provided
|
||||
pass
|
||||
template_file = "헤이셀러양식.xlsx"
|
||||
with xw.App(visible=False) as app:
|
||||
template_wb = app.books.open(template_file)
|
||||
template_ws = template_wb.sheets[0]
|
||||
|
||||
new_wb = xw.Book()
|
||||
new_ws = new_wb.sheets[0]
|
||||
|
||||
# Copy the template sheet to the new workbook
|
||||
template_ws.api.Copy(Before=new_ws.api)
|
||||
new_ws = new_wb.sheets[0]
|
||||
|
||||
# Write data to the new workbook
|
||||
new_ws.range('E3:E53').value = [[v] for v in chunk['타오바오URL']]
|
||||
new_ws.range('B3:B53').value = [[v] for v in chunk['상품명']]
|
||||
new_ws.range('D3:D53').value = [[v] for v in chunk['가격']]
|
||||
new_ws.range('A3:A53').value = [[v] for v in chunk['카테고리']]
|
||||
|
||||
new_wb.save(output_file)
|
||||
new_wb.close()
|
||||
template_wb.close()
|
||||
self.log_signal.emit(f"Exported {output_file}")
|
||||
|
||||
os.startfile(self.output_folder)
|
||||
|
|
@ -99,6 +134,7 @@ class ExportThread(QThread):
|
|||
return ' '.join(prefix + suffix)
|
||||
return title
|
||||
|
||||
|
||||
class ExcelProcessorApp(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
|
@ -111,9 +147,9 @@ class ExcelProcessorApp(QWidget):
|
|||
self.source_file_path = None
|
||||
|
||||
def initUI(self):
|
||||
self.setWindowTitle('WRMC TaomanXLS')
|
||||
self.setGeometry(100, 100, 450, 600)
|
||||
self.setFixedSize(450, 600)
|
||||
self.setWindowTitle('Excel Processor')
|
||||
self.setGeometry(100, 100, 300, 650)
|
||||
self.setFixedSize(300, 650)
|
||||
|
||||
main_layout = QVBoxLayout()
|
||||
|
||||
|
|
@ -126,8 +162,8 @@ class ExcelProcessorApp(QWidget):
|
|||
|
||||
self.source_button = QPushButton('소싱맨 읽기')
|
||||
self.source_button.setMinimumHeight(70)
|
||||
self.source_button.setEnabled(False)
|
||||
self.source_button.clicked.connect(self.read_source)
|
||||
self.source_button.setEnabled(False) # 소싱맨 푸쉬 버튼 비활성화
|
||||
button_layout.addWidget(self.source_button)
|
||||
|
||||
self.export_button = QPushButton('출력')
|
||||
|
|
@ -162,6 +198,26 @@ class ExcelProcessorApp(QWidget):
|
|||
ban_layout.addWidget(self.ban_input)
|
||||
shuffle_layout.addLayout(ban_layout)
|
||||
|
||||
# 가격제한 체크박스와 CommaSpinBox, QLabel 추가
|
||||
price_limit_layout = QHBoxLayout()
|
||||
self.price_limit_checkbox = QCheckBox('가격제한')
|
||||
self.price_limit_checkbox.stateChanged.connect(self.toggle_price_limit)
|
||||
price_limit_layout.addWidget(self.price_limit_checkbox)
|
||||
|
||||
self.price_limit_spinbox = CommaSpinBox()
|
||||
self.price_limit_spinbox.setRange(1000, 1000000)
|
||||
self.price_limit_spinbox.setValue(10000)
|
||||
self.price_limit_spinbox.setSingleStep(1000)
|
||||
self.price_limit_spinbox.setSuffix(" 원")
|
||||
self.price_limit_spinbox.setEnabled(False) # 기본값은 비활성화
|
||||
price_limit_layout.addWidget(self.price_limit_spinbox)
|
||||
|
||||
self.price_limit_label = QLabel('이상')
|
||||
self.price_limit_label.setEnabled(False) # 기본값은 비활성화
|
||||
price_limit_layout.addWidget(self.price_limit_label)
|
||||
|
||||
shuffle_layout.addLayout(price_limit_layout)
|
||||
|
||||
main_layout.addLayout(shuffle_layout)
|
||||
|
||||
# Second layout with radio buttons
|
||||
|
|
@ -171,7 +227,7 @@ class ExcelProcessorApp(QWidget):
|
|||
radio_layout.addWidget(self.percent_radio)
|
||||
|
||||
self.hayseller_radio = QRadioButton('헤이셀러')
|
||||
self.hayseller_radio.setEnabled(False)
|
||||
self.hayseller_radio.setEnabled(False) # 헤이셀러 라디오 버튼 비활성화
|
||||
radio_layout.addWidget(self.hayseller_radio)
|
||||
|
||||
main_layout.addLayout(radio_layout)
|
||||
|
|
@ -184,7 +240,7 @@ class ExcelProcessorApp(QWidget):
|
|||
main_layout.addLayout(log_layout)
|
||||
|
||||
# Footer layout with developer label
|
||||
self.developer_label = QLabel('by 내차는 언제타냐')
|
||||
self.developer_label = QLabel('제작자: Your Name')
|
||||
main_layout.addWidget(self.developer_label, alignment=Qt.AlignCenter)
|
||||
|
||||
self.setLayout(main_layout)
|
||||
|
|
@ -228,7 +284,7 @@ class ExcelProcessorApp(QWidget):
|
|||
self.log(f"Reading file: {file_path}")
|
||||
try:
|
||||
df = pd.read_excel(file_path, sheet_name='추출상점')
|
||||
required_columns = ["퍼센티카테고리", "가격", "상품명", "태그", "타오바오URL"]
|
||||
required_columns = ["퍼센티카테고리", "가격", "상품명", "태그", "타오바오URL", "카테고리"]
|
||||
if all(col in df.columns for col in required_columns):
|
||||
self.log(f"Successfully read data from {file_path}")
|
||||
return df[required_columns], file_path
|
||||
|
|
@ -264,6 +320,8 @@ class ExcelProcessorApp(QWidget):
|
|||
ban_words = [word.strip() for word in ban_words if word.strip()]
|
||||
|
||||
shuffle_title = self.shuffle_checkbox.isChecked()
|
||||
price_limit_enabled = self.price_limit_checkbox.isChecked()
|
||||
price_limit = self.price_limit_spinbox.value()
|
||||
|
||||
export_format = "퍼센티" if self.percent_radio.isChecked() else "헤이셀러"
|
||||
self.log(f"Exporting data in {export_format} format")
|
||||
|
|
@ -284,7 +342,7 @@ class ExcelProcessorApp(QWidget):
|
|||
self.log("출력 폴더를 선택하지 않았습니다.")
|
||||
return
|
||||
|
||||
self.export_thread = ExportThread(data, export_format, output_folder, original_file_name, exclude_words, ban_words, shuffle_title)
|
||||
self.export_thread = ExportThread(data, export_format, output_folder, original_file_name, exclude_words, ban_words, shuffle_title, price_limit_enabled, price_limit)
|
||||
self.export_thread.log_signal.connect(self.log)
|
||||
self.export_thread.finished_signal.connect(self.on_export_finished)
|
||||
self.export_button.setEnabled(False)
|
||||
|
|
@ -293,12 +351,18 @@ class ExcelProcessorApp(QWidget):
|
|||
def on_export_finished(self):
|
||||
self.export_button.setEnabled(True)
|
||||
|
||||
def toggle_price_limit(self):
|
||||
state = self.price_limit_checkbox.isChecked()
|
||||
self.price_limit_spinbox.setEnabled(state)
|
||||
self.price_limit_label.setEnabled(state)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
ex = ExcelProcessorApp()
|
||||
|
||||
|
||||
# Add signal to save config on exit
|
||||
app.aboutToQuit.connect(ex.save_config)
|
||||
|
||||
|
||||
ex.show()
|
||||
sys.exit(app.exec_())
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue