수정중

This commit is contained in:
R5600U_PC 2024-10-02 06:54:10 +09:00
parent 6a96c6e4ed
commit 3f3a86e34a
11 changed files with 33064 additions and 86 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -159,7 +159,7 @@ class BrowserController:
def get_product_name(self, index): def get_product_name(self, index):
"""해당 상품의 이름을 가져옵니다. 오류 발생 시 '수집 오류 발생' 반환""" """해당 상품의 이름을 가져옵니다. 오류 발생 시 '수집 오류 발생' 반환"""
try: try:
product_name_xpath = f"//div[{index}]/li/div/div/div[2]/div/div/div[1]/div[1]/span[2]" product_name_xpath = f"//div[{index}]/div/li/div/div/div[2]/div/div/div[1]/div[1]/span[2]"
product_name_element = self.page.query_selector(product_name_xpath) product_name_element = self.page.query_selector(product_name_xpath)
return product_name_element.inner_text().strip() return product_name_element.inner_text().strip()
except Exception as e: except Exception as e:
@ -394,12 +394,20 @@ class BrowserController:
except Exception as e: except Exception as e:
self.logger.debug(f"이미지 붙여넣기 중 오류: {e}", exc_info=True) self.logger.debug(f"이미지 붙여넣기 중 오류: {e}", exc_info=True)
def save_and_ecs_product_edit(self):
"""상품 수정 후 저장 버튼 클릭"""
try:
self.page.click('button:has-text("저장하기")')
self.page.keyboard.press("Escape") # ESC로 다이얼로그 닫기
self.logger.debug("상품 수정 내용 저장 및 ECS 완료.")
except Exception as e:
self.logger.debug(f"저장 버튼 클릭 중 오류: {e}", exc_info=True)
def save_product_edit(self): def save_product_edit(self):
"""상품 수정 후 저장 버튼 클릭""" """상품 수정 후 저장 버튼 클릭"""
try: try:
self.page.click('button:has-text("저장하기")') self.page.click('button:has-text("저장하기")')
self.logger.debug("상품 수정 내용 저장 완료.") self.logger.debug("상품 수정 내용 저장 완료.")
self.page.keyboard.press("Escape") # ESC로 다이얼로그 닫기
except Exception as e: except Exception as e:
self.logger.debug(f"저장 버튼 클릭 중 오류: {e}", exc_info=True) self.logger.debug(f"저장 버튼 클릭 중 오류: {e}", exc_info=True)

84
gui.py
View File

@ -304,88 +304,6 @@ class TranslationApp(QWidget):
self.detail_progress_bar.setValue(percentage) self.detail_progress_bar.setValue(percentage)
self.detail_progress_bar.setFormat(f"{current_value}/{total_value}개 완료 [{percentage}%]") self.detail_progress_bar.setFormat(f"{current_value}/{total_value}개 완료 [{percentage}%]")
# def start_translation(self):
# self.logger.debug('번역 작업을 시작합니다...')
# self.running = True # 번역 작업이 시작됨
# try:
# # 1. "신규 상품 등록" 페이지로 이동
# self.logger.debug('신규 상품 등록 페이지로 이동 중...')
# self.browser_controller.go_to_new_product_page()
# # 2. 총 상품 수 수집
# self.browser_controller.scroll_page_to_bottom()
# total_products = self.browser_controller.get_total_product_count()
# if total_products == 0:
# self.logger.debug('수집할 상품이 없습니다. 작업을 종료합니다.')
# return
# self.total_progress_bar.setMaximum(total_products)
# self.total_progress_bar.setValue(0)
# completed_count = 0
# self.update_total_progress(completed_count,total_products)
# page_number = 1
# # 4. 현재 페이지의 모든 "세부사항 수정 및 업로드" 버튼 찾기
# product_buttons = self.browser_controller.get_product_edit_buttons()
# while self.running:
# self.logger.debug(f'현재 페이지: {page_number}')
# if not product_buttons:
# self.logger.debug('수정할 상품이 없습니다. 번역 작업을 종료합니다.')
# break
# # 5. 각 상품에 대해 번역 작업 수행
# for index, button in enumerate(product_buttons, start=1):
# if not self.running:
# self.logger.debug('번역 작업이 중단되었습니다.')
# break
# self.logger.debug(f'{index}/{len(product_buttons)}: 세부사항 수정 작업 중...')
# # 상품명 수집 및 수집오류 처리
# product_name = self.browser_controller.get_product_name(index)
# if product_name == "수집 오류 발생":
# self.logger.debug('상품 수집 오류, 다음 상품으로 넘어갑니다.')
# continue
# # 상품 수정 다이얼로그 열기
# self.browser_controller.open_product_edit_dialog(button)
# # 옵션 수정
# self.start_stage(0)
# self.edit_option()
# self.complete_stage(0)
# # 상세페이지 수정
# self.start_stage(1)
# self.detail_trans()
# self.complete_stage(1)
# # 수정 후 저장
# self.logger.debug('상품 세부사항 저장 중...')
# self.browser_controller.save_product_edit()
# completed_count += 1
# self.update_total_progress(completed_count,total_products)
# self.logger.debug('상품 수정 완료.')
# # 6. 다음 페이지로 이동 (있으면)
# if not self.browser_controller.go_to_next_page():
# self.logger.debug('더 이상 페이지가 없습니다. 작업을 종료합니다.')
# break
# page_number += 1
# if self.running:
# self.logger.debug('모든 상품 번역 및 저장 완료.')
# self.running = False # 작업 종료 후 상태를 False로 전환
# except Exception as e:
# self.logger.debug(f"번역 작업 중 오류 발생: {e}", exc_info=True)
# self.running = False
def start_translation(self): def start_translation(self):
self.logger.debug('번역 작업을 시작합니다...') self.logger.debug('번역 작업을 시작합니다...')
self.running = True # 번역 작업이 시작됨 self.running = True # 번역 작업이 시작됨
@ -447,7 +365,7 @@ class TranslationApp(QWidget):
# 수정 후 저장 # 수정 후 저장
self.logger.debug('상품 세부사항 저장 중...') self.logger.debug('상품 세부사항 저장 중...')
self.browser_controller.save_product_edit() self.browser_controller.save_and_ecs_product_edit()
completed_count += 1 completed_count += 1
self.update_total_progress(completed_count, total_products) self.update_total_progress(completed_count, total_products)

View File

@ -1,3 +1,5 @@
import pyautogui
class OptionHandler: class OptionHandler:
def __init__(self, page, logger, vertexAI): def __init__(self, page, logger, vertexAI):
self.page = page self.page = page
@ -11,8 +13,64 @@ class OptionHandler:
'prices': {} # 가격 정보 추가 'prices': {} # 가격 정보 추가
} }
def process_options(self, max_option_count=10): def process_options(self, max_option_count=10):
"""옵션 상품을 처리하는 메서드"""
try:
# 1. 단일 옵션인지 판단
if self.is_single_option():
self.logger.debug("단일 옵션 상품입니다. 옵션 수정 과정을 생략합니다.")
return
# 2. 전체 옵션 체크박스 상태 확인
if not self.is_all_options_checked():
self.logger.debug("옵션이 일부만 체크된 상태입니다. 옵션 수정이 완료된 상품으로 판단하여 패스합니다.")
return
# 3. 가격 낮은 순 정렬 클릭
self.low_order_click()
# 4. 옵션 정보 수집 및 번역
option_info = self.collect_options_info()
# Vertex AI를 통해 옵션명을 번역
self.logger.debug(f"수집된 원본 옵션 정보: {self.option_info['original_names']}")
try:
translated_options = self.vertexAItranslator.translate_options(self.option_info['original_names'])
self.logger.debug(f"번역된 옵션 정보: {translated_options}")
# 5. 번역된 옵션명 편집칸에 입력
self.logger.debug("번역된 옵션명을 입력합니다.")
self.apply_translated_options(translated_options, self.option_info['edit_fields'])
except ValueError as ve:
# 안전 필터로 차단된 경우
if "SAFETY" in str(ve):
self.logger.error(f"안전 필터에 의해 번역 요청이 차단되었습니다. {ve}")
self.logger.debug("퍼센티 자체 AI옵션을 실행(Alt+Q)")
# pyautogui를 통해 Alt+Q 키보드 입력을 보냄
pyautogui.hotkey('alt', 'q')
# 대체 옵션 처리 종료 후 바로 리턴하지 않고, 다음 동작으로 넘어감.
# 번역이 차단된 경우에도 나머지 프로세스를 그대로 진행
# 6. 옵션 선택 및 제한 처리
self.adjust_options(self.option_info['checkboxes'], max_option_count)
# 7. 정리된 옵션을 다시 한번 더 가격 낮은 순으로 정렬 클릭
self.low_order_click()
# 8. 저장 버튼 클릭
self.logger.debug("저장 버튼을 클릭합니다.")
self.page.click('button:has-text("저장하기")')
self.logger.debug("옵션 처리 완료.")
except Exception as e:
self.logger.debug(f"옵션 처리 중 오류 발생: {e}", exc_info=True)
return
def process_options_ori(self, max_option_count=10):
"""옵션 상품을 처리하는 메서드""" """옵션 상품을 처리하는 메서드"""
try: try:
# 1. 단일 옵션인지 판단 # 1. 단일 옵션인지 판단