forked from ckh08045/AutoPercenty
번역조정중
This commit is contained in:
parent
3ff8b4baa1
commit
c8e1f742a5
163
ai/deepl.py
163
ai/deepl.py
|
|
@ -20,16 +20,12 @@ def trans(original_text):
|
|||
USER_AGENTS = [
|
||||
# Chrome (Windows 10)
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
|
||||
|
||||
# Edge (Windows 10)
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.0.0",
|
||||
|
||||
# Firefox (Windows 10)
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0",
|
||||
|
||||
# Safari (macOS Monterey)
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15",
|
||||
|
||||
# Opera (Windows 10)
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 OPR/85.0.0.0"
|
||||
]
|
||||
|
|
@ -38,13 +34,6 @@ def trans(original_text):
|
|||
# Start a Selenium driver
|
||||
options = webdriver.ChromeOptions()
|
||||
|
||||
# ua = UserAgent()
|
||||
# ua.user_agent_list = ua.pc_browsers
|
||||
# # 랜덤 PC Agent 선택
|
||||
# random_PC_UA = ua.random
|
||||
# logger.debug(f"UserAgent : {random_PC_UA}")
|
||||
# options.add_argument(f"--user-agent={random_PC_UA}") # 랜덤 user_agent 사용
|
||||
|
||||
options.add_argument(f"user-agent={random_user_agent}")
|
||||
options.add_argument("--disable-blink-features=AutomationControlled")
|
||||
options.add_argument('--ignore-certificate-errors')
|
||||
|
|
@ -65,9 +54,6 @@ def trans(original_text):
|
|||
|
||||
# Reach the deepL website
|
||||
|
||||
options.headless = False # 헤드리스 모드 선택적 비활성화
|
||||
|
||||
|
||||
deepl_url = 'https://www.deepl.com/ko/translator' # 한국어
|
||||
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})") # 속성 변경
|
||||
|
||||
|
|
@ -88,101 +74,74 @@ def trans(original_text):
|
|||
logger.error(f"Error fetching translation:{e}", exc_info=True)
|
||||
content = "Translation failed"
|
||||
|
||||
# Display results
|
||||
# print('#' * 50)
|
||||
# print('Original :', original_text)
|
||||
# print('Translation :', content)
|
||||
# print('#' * 50)
|
||||
|
||||
# Clear button
|
||||
# try:
|
||||
# # button = driver.find_element(By.CSS_SELECTOR, 'div.lmt__clear_text_button_wrapper button')
|
||||
# # button = driver.find_element(By.CSS_SELECTOR, '#translator-source-clear-button path')
|
||||
# button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-testid="translator-source-clear-button"]')))
|
||||
|
||||
# button.click()
|
||||
# except Exception as e:
|
||||
# print("Error clicking clear button:", e)
|
||||
|
||||
# Close the driver
|
||||
driver.quit()
|
||||
|
||||
return content
|
||||
|
||||
# result = trans("全铜芯卧式电机不锈钢底座厚")
|
||||
# print(f"입력 : 全铜芯卧式电机不锈钢底座厚")
|
||||
# print(f"결과 : {result}")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ===========================================
|
||||
|
||||
|
||||
# import time
|
||||
# from selenium import webdriver
|
||||
# from selenium.webdriver.chrome.options import Options
|
||||
# from selenium.webdriver.chrome.service import Service
|
||||
# from selenium.webdriver.common.by import By
|
||||
# from selenium.webdriver.support.ui import WebDriverWait
|
||||
# from selenium.webdriver.support import expected_conditions as EC
|
||||
# from tqdm import tqdm
|
||||
# from selenium_stealth import stealth
|
||||
# from fake_useragent import UserAgent
|
||||
|
||||
|
||||
# def trans(original_text):
|
||||
# # Start a Selenium driver
|
||||
# options = webdriver.ChromeOptions()
|
||||
# ua = UserAgent()
|
||||
# options.add_argument(f"--user-agent={ua.random}") # 랜덤 user_agent 사용
|
||||
# options.add_argument("--disable-blink-features=AutomationControlled")
|
||||
# options.add_argument('--ignore-certificate-errors')
|
||||
# options.add_argument('--ssl-protocol=any')
|
||||
# options.add_argument('--disable-cache')
|
||||
# driver = webdriver.Chrome(options=options)
|
||||
|
||||
# # selenium-stealth 설정 적용
|
||||
# stealth(driver,
|
||||
# languages=["en-US", "en"],
|
||||
# vendor="Google Inc.",
|
||||
# platform="Win32",
|
||||
# webgl_vendor="Intel Inc.",
|
||||
# renderer="Intel Iris OpenGL Engine",
|
||||
# fix_hairline=True,
|
||||
# )
|
||||
|
||||
# # DeepL 웹사이트 접속
|
||||
# deepl_url = 'https://www.deepl.com/ko/translator'
|
||||
# driver.get(deepl_url)
|
||||
def trans_list(original_texts):
|
||||
|
||||
# # 번역할 텍스트 입력
|
||||
# input_area = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".min-h-0:nth-child(1) > div:nth-child(1)")))
|
||||
# input_area.send_keys(original_text)
|
||||
# time.sleep(3) # 네트워크 속도에 따라 조정
|
||||
translated_texts = [] # 번역된 텍스트를 저장할 리스트
|
||||
|
||||
# # 번역 결과 대기 및 추출
|
||||
# try:
|
||||
# WebDriverWait(driver, 10).until(
|
||||
# lambda driver: driver.find_element(By.CSS_SELECTOR, '[data-testid="translator-target-input"]').text.strip() != "")
|
||||
# translation_text = driver.find_element(By.CSS_SELECTOR, '[data-testid="translator-target-input"]')
|
||||
# translated_content = translation_text.text
|
||||
# except Exception as e:
|
||||
# print("Error fetching translation:", e)
|
||||
# translated_content = "Translation failed"
|
||||
# PC 사용자 에이전트
|
||||
USER_AGENTS = [
|
||||
# Chrome (Windows 10)
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
|
||||
# Edge (Windows 10)
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.0.0",
|
||||
# Firefox (Windows 10)
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0",
|
||||
# Safari (macOS Monterey)
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15",
|
||||
# Opera (Windows 10)
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 OPR/85.0.0.0"
|
||||
]
|
||||
random_user_agent = random.choice(USER_AGENTS)
|
||||
|
||||
# # # Clear 버튼 클릭
|
||||
# # try:
|
||||
# # clear_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-testid="translator-source-clear-button"]')))
|
||||
# # clear_button.click()
|
||||
# # except Exception as e:
|
||||
# # print("Error clicking clear button:", e)
|
||||
# Start a Selenium driver
|
||||
options = webdriver.ChromeOptions()
|
||||
|
||||
# # 드라이버 종료
|
||||
# driver.quit()
|
||||
options.add_argument(f"user-agent={random_user_agent}")
|
||||
options.add_argument("--disable-blink-features=AutomationControlled")
|
||||
options.add_argument('--ignore-certificate-errors')
|
||||
options.add_argument('--ssl-protocol=any')
|
||||
options.add_argument('--disable-cache')
|
||||
options.add_argument('--headless')
|
||||
driver = webdriver.Chrome(options=options)
|
||||
|
||||
# selenium-stealth 설정 적용
|
||||
stealth(driver,
|
||||
languages=["en-US", "en"],
|
||||
vendor="Google Inc.",
|
||||
platform="Win32",
|
||||
webgl_vendor="Intel Inc.",
|
||||
renderer="Intel Iris OpenGL Engine",
|
||||
fix_hairline=True,
|
||||
)
|
||||
|
||||
# Reach the deepL website
|
||||
|
||||
# return translated_content
|
||||
deepl_url = 'https://www.deepl.com/ko/translator' # 한국어
|
||||
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})") # 속성 변경
|
||||
|
||||
# trans("微博登录")
|
||||
driver.get(deepl_url)
|
||||
|
||||
# Improved wait for translation to appear
|
||||
for text in original_texts:
|
||||
try:
|
||||
driver.execute_script("document.querySelector('[data-testid=\"translator-source-input\"] div[contenteditable=\"true\"]').textContent = '';")
|
||||
input_field = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-testid="translator-source-input"]')))
|
||||
# input_field.clear() # 입력 필드를 클리어합니다.
|
||||
input_field.send_keys(text)
|
||||
WebDriverWait(driver, 20).until(lambda d: d.execute_script('return document.readyState') == 'complete')
|
||||
|
||||
WebDriverWait(driver, 10).until(
|
||||
lambda driver: driver.find_element(By.CSS_SELECTOR, '[data-testid="translator-target-input"]').text.strip() != "")
|
||||
translation_text = driver.find_element(By.CSS_SELECTOR, '[data-testid="translator-target-input"]')
|
||||
translated_texts.append(translation_text.text)
|
||||
except Exception as e:
|
||||
logging.error(f"Error fetching translation: {e}", exc_info=True)
|
||||
translated_texts.append("Translation failed") # 수정된 예외 처리
|
||||
|
||||
driver.quit()
|
||||
|
||||
return translated_texts
|
||||
|
|
|
|||
158
edit/detail1.py
158
edit/detail1.py
|
|
@ -360,7 +360,7 @@ def modify_detail_page(driver, product_info, gemini, delv_collection, json_naver
|
|||
thumb_data_note = "5"
|
||||
click_and_confirm_tab(driver, thumb_data_note, 10)
|
||||
|
||||
|
||||
product_info_card = None
|
||||
product_keyword = product_info.keyword_title
|
||||
# product_low_cost = product_info.tao_low_price
|
||||
# product_high_cost = product_info.tao_high_price
|
||||
|
|
@ -503,6 +503,10 @@ def modify_detail_page(driver, product_info, gemini, delv_collection, json_naver
|
|||
logger.debug(f"가격정보 생성 중 에러 : {e}", exc_info=True)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
try:
|
||||
logger.debug("HTML 수정 버튼 클릭 .")
|
||||
html_btn_by_contains_xpath="//button[contains(.,'소스')]"
|
||||
|
|
@ -551,29 +555,17 @@ def modify_detail_page(driver, product_info, gemini, delv_collection, json_naver
|
|||
|
||||
logger.debug("현재 속성값 수집 완료")
|
||||
|
||||
# # ============번역을 위한 사전작업============
|
||||
# 이미지 Url 수집
|
||||
# translated_image_urls = [] # 번역된 이미지 URL들을 저장할 리스트
|
||||
detail_images = fetch_image_urls(original_html_tags)
|
||||
# logger.debug(f"detail_images URLs \n {detail_images}")
|
||||
product_info.detail_image_urls = detail_images
|
||||
|
||||
# 원본 URL을 빈문자열로 대체
|
||||
# logger.debug("원본 URL을 빈 문자열로 대체")
|
||||
# for original_url in detail_images:
|
||||
# current_value = current_value.replace(original_url, "")
|
||||
# logger.debug("새로운 data-value 값으로 설정되었습니다.")
|
||||
# # ============번역을 위한 사전작업============
|
||||
|
||||
logger.debug("product_info_card 결합.")
|
||||
new_value = product_info_card +'<br><br>' + cost_add_text +'<br><br>' +original_html_tags
|
||||
# textarea.send_keys(product_info_card)
|
||||
time.sleep(0.2)
|
||||
# logger.debug("product_info_card 결합.")
|
||||
# new_value = product_info_card +'<br><br>' + cost_add_text +'<br><br>' +original_html_tags
|
||||
# # textarea.send_keys(product_info_card)
|
||||
# time.sleep(0.2)
|
||||
|
||||
logger.debug("결합.")
|
||||
# 결합된 값을 다시 textarea에 설정
|
||||
# # data-value 속성을 새로운 값으로 설정합니다.
|
||||
driver.execute_script("arguments[0].setAttribute('data-value', arguments[1]);", textarea, new_value)
|
||||
# logger.debug("결합.")
|
||||
# # 결합된 값을 다시 textarea에 설정
|
||||
# # # data-value 속성을 새로운 값으로 설정합니다.
|
||||
# driver.execute_script("arguments[0].setAttribute('data-value', arguments[1]);", textarea, new_value)
|
||||
|
||||
# # driver.execute_script("arguments[0].innerHTML = arguments[1]", textarea, new_value)
|
||||
# # driver.execute_script("arguments[0].innerHTML = arguments[1]", detail_content, new_value);
|
||||
|
|
@ -602,45 +594,40 @@ def modify_detail_page(driver, product_info, gemini, delv_collection, json_naver
|
|||
except Exception as e:
|
||||
logger.debug(f"HTML 전환 수정 중 에러발생 : {e}", exc_info=True)
|
||||
|
||||
try:
|
||||
# 상세페이지 내용에 텍스트 추가
|
||||
logger.debug("커서위치 맞추기")
|
||||
detail_content.send_keys(Keys.LEFT)
|
||||
detail_content.send_keys(Keys.HOME)
|
||||
detail_content.send_keys(Keys.ENTER)
|
||||
detail_content.send_keys(Keys.ENTER)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.HOME)
|
||||
detail_content.send_keys(Keys.HOME)
|
||||
|
||||
# contents 변수의 값이 None이 아닐 때만 send_keys 메서드를 호출합니다.
|
||||
if aicontents is not None:
|
||||
detail_content.send_keys(aicontents)
|
||||
logger.debug(f"AI 컨텐츠 입력완료")
|
||||
|
||||
else:
|
||||
# contents 변수가 None일 때의 대체 처리
|
||||
# 예: detail_content.send_keys("") 또는 아무 동작도 수행하지 않음
|
||||
pass
|
||||
|
||||
time.sleep(0.5)
|
||||
|
||||
detail_content.send_keys(Keys.ENTER)
|
||||
detail_content.send_keys(Keys.ENTER)
|
||||
detail_content.send_keys(Keys.ENTER)
|
||||
except Exception as e:
|
||||
logger.error(f"AI 컨텐츠 입력 중 에러발생 : {e}", exc_info=True)
|
||||
|
||||
|
||||
|
||||
trans_img_tag = login_info["whether_modifyImageTanslation"]
|
||||
logger.debug(f"whether_modifyImageTanslation : {trans_img_tag}")
|
||||
|
||||
if login_info["whether_modifyImageTanslation"]:
|
||||
logger.debug("상세페이지 이미지 번역 시작")
|
||||
|
||||
logger.debug("HTML 수정 버튼을 클릭하여 원본이밎URL 수집 및 삭제")
|
||||
click_element(driver, 'XPATH', html_btn_xpath, 5, 'js')
|
||||
|
||||
# # ============번역을 위한 사전작업============
|
||||
# 이미지 Url 수집
|
||||
# translated_image_urls = [] # 번역된 이미지 URL들을 저장할 리스트
|
||||
detail_images = fetch_image_urls(original_html_tags)
|
||||
|
||||
current_value = textarea.get_attribute("data-value")
|
||||
original_html_tags = original_html(current_value)
|
||||
|
||||
# logger.debug(f"detail_images URLs \n {detail_images}")
|
||||
product_info.detail_image_urls = detail_images
|
||||
|
||||
# 원본 URL을 빈문자열로 대체
|
||||
logger.debug("원본 URL을 빈 문자열로 대체")
|
||||
for original_url in detail_images:
|
||||
renwed_current_value = current_value.replace(original_url, "")
|
||||
|
||||
# data-value 속성을 새로운 값으로 설정합니다.
|
||||
driver.execute_script("arguments[0].setAttribute('data-value', arguments[1]);", textarea, renwed_current_value)
|
||||
logger.debug("새로운 data-value 값으로 설정되었습니다.")
|
||||
# # ============번역을 위한 사전작업============
|
||||
|
||||
logger.debug("HTML 수정 버튼을 다시 클릭하여 에디터로 돌아오기")
|
||||
click_element(driver, 'XPATH', html_btn_xpath, 5, 'js')
|
||||
|
||||
try:
|
||||
for i, detail_image in enumerate(detail_images):
|
||||
logger.debug(f"상세페이지 {i+1}번째 이미지 번역 시작")
|
||||
|
|
@ -661,7 +648,68 @@ def modify_detail_page(driver, product_info, gemini, delv_collection, json_naver
|
|||
|
||||
logger.debug("====번역이미지 붙여넣기 완료=====")
|
||||
|
||||
|
||||
logger.debug("HTML 수정 버튼을 클릭하여 텍스트 정보 삽입 준비")
|
||||
click_element(driver, 'XPATH', html_btn_xpath, 5, 'js')
|
||||
time.sleep(0.5)
|
||||
try:
|
||||
# 상세페이지 내용에 텍스트 추가
|
||||
logger.debug("커서위치 맞추기")
|
||||
detail_content.send_keys(Keys.LEFT)
|
||||
detail_content.send_keys(Keys.HOME)
|
||||
detail_content.send_keys(Keys.ENTER)
|
||||
detail_content.send_keys(Keys.ENTER)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.HOME)
|
||||
detail_content.send_keys(Keys.HOME)
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
logger.debug("product_info_card 결합.")
|
||||
new_value = product_info_card +'<br><br>' + cost_add_text +'<br><br>' + original_html_tags
|
||||
# textarea.send_keys(product_info_card)
|
||||
time.sleep(0.2)
|
||||
|
||||
logger.debug("product_info_card 입력")
|
||||
# 결합된 값을 다시 textarea에 설정
|
||||
# # data-value 속성을 새로운 값으로 설정합니다.
|
||||
driver.execute_script("arguments[0].setAttribute('data-value', arguments[1]);", textarea, new_value)
|
||||
|
||||
logger.debug("HTML 수정 버튼을 다시 클릭하여 기본편집페이지로 돌아오기")
|
||||
click_element(driver, 'XPATH', html_btn_xpath, 5, 'js')
|
||||
|
||||
# 상세페이지 내용에 텍스트 추가
|
||||
logger.debug("커서위치 맞추기")
|
||||
detail_content.send_keys(Keys.LEFT)
|
||||
detail_content.send_keys(Keys.HOME)
|
||||
detail_content.send_keys(Keys.ENTER)
|
||||
detail_content.send_keys(Keys.ENTER)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.UP)
|
||||
detail_content.send_keys(Keys.HOME)
|
||||
detail_content.send_keys(Keys.HOME)
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
# contents 변수의 값이 None이 아닐 때만 send_keys 메서드를 호출합니다.
|
||||
if aicontents is not None:
|
||||
detail_content.send_keys(aicontents)
|
||||
logger.debug(f"AI 컨텐츠 입력완료")
|
||||
|
||||
else:
|
||||
# contents 변수가 None일 때의 대체 처리
|
||||
# 예: detail_content.send_keys("") 또는 아무 동작도 수행하지 않음
|
||||
pass
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"AI 컨텐츠 입력 중 에러발생 : {e}", exc_info=True)
|
||||
|
||||
|
||||
logger.debug("상세페이지 편집 저장")
|
||||
|
||||
click_element(driver, "XPATH", save_button_xpath, 5, 'js')
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from selenium.webdriver.common.action_chains import ActionChains
|
|||
from selenium.webdriver.common.keys import Keys
|
||||
import time
|
||||
from edit.action_elements import click_element, return_element, click_and_confirm_tab
|
||||
from ai.deepl import trans
|
||||
from ai.deepl import trans, trans_list
|
||||
from ai.deepl_with_playwright import trans_text, trans_list_text
|
||||
# from ai.compare import find_most_similar_image_by_one
|
||||
import re
|
||||
|
|
@ -197,7 +197,15 @@ def edit_option(driver, option_type, option_count):
|
|||
logger.debug("전체 체크박스 선택 해제")
|
||||
# select_all_checkbox_xpath = f"//div[@id='productMainContentContainerId']/div/div[2]/div/div/div[2]/div/div[{option_type}]/div/div/div[2]/div/div/div[5]/div/div/label/span"
|
||||
select_all_checkbox_xpath = f"//div[{option_type}]/div/div/div[2]/div/div/div[4]/div[2]/div[1]/label/span[1]"
|
||||
|
||||
|
||||
logger.debug("전체체크박스의 상태확인")
|
||||
select_all_checkbox_state_xpath = f"//div[{option_type}]/div/div/div[2]/div/div/div[4]/div[2]/div[1]/label/span[1]/input"
|
||||
select_all_checkbox_state_element = return_element(driver, 'XPATH', select_all_checkbox_state_xpath, 10)
|
||||
# select_all_checkbox_state_element = driver.find_element_by_xpath(select_all_checkbox_state_xpath)
|
||||
if select_all_checkbox_state_element.get_attribute("aria-checked") == "mixed":
|
||||
logger.debug("전체체크박스의 일부 선택상태 확인")
|
||||
click_element(driver, 'XPATH', select_all_checkbox_xpath, 10, 'js')
|
||||
|
||||
click_element(driver, 'XPATH', select_all_checkbox_xpath, 10, 'js')
|
||||
logger.debug(f"옵션타입 {option_type} 전체 선택 체크박스 해제")
|
||||
time.sleep(1)
|
||||
|
|
@ -265,7 +273,8 @@ def option_name_trans(driver, product_info, option_type_number, option_count, al
|
|||
# logger.debug(f"원본옵션명 집합 \n {cleaned_ori_text}")
|
||||
|
||||
logger.debug("번역 시행")
|
||||
deepl_trans_optionNames = trans_list_text(ori_optionNames) # DeepL 번역 함수
|
||||
# deepl_trans_optionNames = trans_list_text(ori_optionNames) # DeepL 번역 함수
|
||||
deepl_trans_optionNames = trans_list(ori_optionNames) # DeepL 번역 함수
|
||||
# trans_optionNames_text = trans_text(cleaned_ori_text) # DeepL_with_playwright 번역 함수
|
||||
|
||||
# trans_optionNames_text = trans(cleaned_ori_text) # DeepL 번역 함수
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from googletrans import Translator
|
||||
# from img_trans.src.deepl_ori import trans
|
||||
from ai.deepl import trans
|
||||
from ai.deepl import trans, trans_list
|
||||
from ai.deepl_with_playwright import trans_list_text, trans_text
|
||||
from translatepy import Translator
|
||||
import logging
|
||||
|
|
@ -49,7 +49,8 @@ def translate_texts_deepl(texts):
|
|||
|
||||
# DeepL로 전체 텍스트 번역
|
||||
try:
|
||||
translated_texts = trans_list_text(texts)
|
||||
translated_texts = trans_list(texts)
|
||||
# translated_texts = trans_list_text(texts)
|
||||
# "가격"이 포함된 경우 빈 문자열로 대체
|
||||
translated_texts = [text if "가격" not in text else "" for text in translated_texts]
|
||||
|
||||
|
|
|
|||
|
|
@ -223,25 +223,31 @@ def modify_products(driver, gemini, mongo_config, login_info, set_num_modify):
|
|||
|
||||
if incomplete_steps is True:
|
||||
pass
|
||||
elif isinstance(incomplete_steps, list) and len(incomplete_steps) < 6:
|
||||
# incomplete_steps가 리스트 타입이고, 길이가 6 미만인 경우에만 미완성된 단계들에 대해 처리합니다.
|
||||
logger.debug(f"총 [{len(incomplete_steps)}]개의 미완성 목록을 발견")
|
||||
logger.debug(f"미완성 스텝 목록 : {incomplete_steps}")
|
||||
product_infos[i-1] = autoPercentyProductsDB.get_product_info_by_id(product_id)
|
||||
logger.debug("기존 product_info를 가져옵니다.")
|
||||
# 완료되지 않은 단계에 해당하는 작업을 수행합니다.
|
||||
click_to_product_title_for_modify_xpath = f"//div[{i}]/li/div/div/div[2]/div/div/div/div"
|
||||
click_element(driver, 'XPATH', click_to_product_title_for_modify_xpath, 10, 'js')
|
||||
logger.debug("상품 수정 페이지 클릭")
|
||||
time.sleep(2)
|
||||
for step_name, action, args in steps_and_actions:
|
||||
if step_name in incomplete_steps:
|
||||
# 각 단계별 실행 여부 판단
|
||||
if step_conditions.get(step_name, False):
|
||||
perform_step(autoPercentyProductsDB, step_name, action, current_user, *args)
|
||||
autoPercentyProductsDB.finalize_product_processing(product_id, current_user, product_infos[i-1])
|
||||
logger.info(f"상품 ID {product_id}의 미완성 목록을 완성했습니다.")
|
||||
pass
|
||||
|
||||
# 아래는 미완성 목록이 있을 경우 해당부분만 실행하는 코드였으나, 순서대로 코드가 실행되지 않을 경우
|
||||
# 다음 단계의 코드 실행중 에러발생여지가 많아서, 완료코드가 들어간 ID가 아닌 이상 모든 ID에 대해
|
||||
# 모든 단계를 실행하게 하기위해 아래 부분은 주석처리
|
||||
# elif isinstance(incomplete_steps, list) and len(incomplete_steps) < 6:
|
||||
# # incomplete_steps가 리스트 타입이고, 길이가 6 미만인 경우에만 미완성된 단계들에 대해 처리합니다.
|
||||
# logger.debug(f"총 [{len(incomplete_steps)}]개의 미완성 목록을 발견")
|
||||
# logger.debug(f"미완성 스텝 목록 : {incomplete_steps}")
|
||||
# product_infos[i-1] = autoPercentyProductsDB.get_product_info_by_id(product_id)
|
||||
# logger.debug("기존 product_info를 가져옵니다.")
|
||||
# # 완료되지 않은 단계에 해당하는 작업을 수행합니다.
|
||||
# click_to_product_title_for_modify_xpath = f"//div[{i}]/li/div/div/div[2]/div/div/div/div"
|
||||
# click_element(driver, 'XPATH', click_to_product_title_for_modify_xpath, 10, 'js')
|
||||
# logger.debug("상품 수정 페이지 클릭")
|
||||
# time.sleep(2)
|
||||
# for step_name, action, args in steps_and_actions:
|
||||
# if step_name in incomplete_steps:
|
||||
# # 각 단계별 실행 여부 판단
|
||||
# if step_conditions.get(step_name, False):
|
||||
# perform_step(autoPercentyProductsDB, step_name, action, current_user, *args)
|
||||
# autoPercentyProductsDB.finalize_product_processing(product_id, current_user, product_infos[i-1])
|
||||
# logger.info(f"상품 ID {product_id}의 미완성 목록을 완성했습니다.")
|
||||
# pass
|
||||
|
||||
|
||||
else:
|
||||
# 여기에는 incomplete_steps가 False이거나 리스트의 길이가 6인 경우.
|
||||
# 이는 상품이 수정된 적 없거나 모든 단계가 미완성인 상태를 의미.
|
||||
|
|
|
|||
Loading…
Reference in New Issue