This commit is contained in:
parent
d8a7aecf7f
commit
87fd855ef6
84
option.py
84
option.py
|
|
@ -117,7 +117,7 @@ class OptionHandler:
|
|||
try:
|
||||
selected_translated_options = []
|
||||
|
||||
total_options_count = len([self.option_info]['original_names'])
|
||||
total_options_count = len(self.option_info['original_names'])
|
||||
|
||||
await self.low_order_click()
|
||||
|
||||
|
|
@ -169,7 +169,10 @@ class OptionHandler:
|
|||
return
|
||||
|
||||
# 2. 전체 옵션 체크박스 상태 확인
|
||||
if not await self.is_all_options_checked():
|
||||
click_to_check_to_all = True
|
||||
self.logger.debug(f"언제나 전체체크에서 시작 - {click_to_check_to_all}")
|
||||
|
||||
if not await self.is_all_options_checked(click_to_check_to_all):
|
||||
self.logger.debug("옵션이 일부만 체크된 상태입니다. 옵션 수정이 완료된 상품으로 판단하여 패스합니다.")
|
||||
return
|
||||
|
||||
|
|
@ -191,7 +194,7 @@ class OptionHandler:
|
|||
|
||||
translation_success = True # 번역 성공
|
||||
|
||||
except ValueError as ve:
|
||||
except Exception as ve:
|
||||
if "SAFETY" in str(ve):
|
||||
self.logger.error(f"안전 필터에 의해 번역 요청이 차단되었습니다. {ve}")
|
||||
self.logger.debug(f"퍼센티 자체 AI번역 사용 시도")
|
||||
|
|
@ -270,18 +273,50 @@ class OptionHandler:
|
|||
return False
|
||||
|
||||
|
||||
async def is_all_options_checked(self):
|
||||
"""전체 옵션 체크박스 상태를 확인 (전체 체크 여부)"""
|
||||
async def is_all_options_checked(self, click_to_check_to_all=False):
|
||||
"""
|
||||
전체 옵션 체크박스 상태를 확인하고 필요한 경우 전체 체크 상태로 변경.
|
||||
|
||||
Args:
|
||||
click_to_check_to_all (bool): 전체 옵션을 체크할지 여부. True면 전체 체크 상태로 변경.
|
||||
|
||||
Returns:
|
||||
bool: 전체 체크 상태일 경우 True, 일부 또는 전체 체크 해제 상태일 경우 False.
|
||||
"""
|
||||
try:
|
||||
checkbox = await self.page.query_selector(self.total_options_selector)
|
||||
if checkbox:
|
||||
self.logger.debug("전체 옵션이 체크되어 있음")
|
||||
# 전체 체크박스 요소 가져오기
|
||||
checkbox_element = await self.page.query_selector(self.is_all_option_checked_selector)
|
||||
if not checkbox_element:
|
||||
self.logger.error("전체 체크박스 요소를 찾을 수 없습니다.")
|
||||
return False
|
||||
|
||||
# 체크박스 상태 확인
|
||||
aria_checked = await checkbox_element.get_attribute('aria-checked')
|
||||
self.logger.debug(f"aria_checked : {aria_checked}----------------")
|
||||
|
||||
|
||||
# 체크박스 상태 판단
|
||||
if aria_checked == 'mixed':
|
||||
self.logger.debug("전체 체크박스가 일부만 체크되어 있음")
|
||||
|
||||
if click_to_check_to_all:
|
||||
# 전체 체크 수행
|
||||
await checkbox_element.click()
|
||||
self.logger.debug("전체 체크박스를 전체 체크 상태로 변경")
|
||||
return True # 전체 체크 후 True 반환
|
||||
else:
|
||||
return False # 일부 체크 상태만 확인 시 False 반환
|
||||
|
||||
elif aria_checked == 'true' or aria_checked is None:
|
||||
self.logger.debug("전체 체크박스가 완전 체크 상태임")
|
||||
return True
|
||||
checkbox_partial = await self.page.query_selector(self.is_all_option_checked_selector)
|
||||
self.logger.debug("일부 옵션이 체크되어 있으므로 수정완료 상품으로 판단.")
|
||||
return checkbox_partial is None # 일부 체크 시 False
|
||||
|
||||
else:
|
||||
self.logger.debug("전체 체크박스가 체크 해제 상태임")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"전체 옵션 체크박스 확인 중 오류 발생: {e}", exc_info=True)
|
||||
self.logger.error(f"전체 옵션 체크박스 상태 확인 중 오류 발생: {e}", exc_info=True)
|
||||
return False
|
||||
|
||||
async def collect_options_info(self):
|
||||
|
|
@ -320,6 +355,21 @@ class OptionHandler:
|
|||
self.option_info['edit_fields'][original_name] = edit_field_element if edit_field_element else None
|
||||
self.option_info['checkboxes'].append(checkbox_element if checkbox_element else None)
|
||||
|
||||
# 체크박스 상태 수집 (체크 여부는 클래스 이름으로 판단)
|
||||
checkbox_state = None
|
||||
if checkbox_element:
|
||||
checkbox_classes = await checkbox_element.get_attribute('class')
|
||||
if 'ant-checkbox-checked' in checkbox_classes:
|
||||
checkbox_state = True
|
||||
elif 'ant-checkbox' in checkbox_classes:
|
||||
checkbox_state = False
|
||||
|
||||
self.option_info['checkboxes'].append({'option_name': original_name, 'checked': checkbox_state})
|
||||
|
||||
self.logger.debug(f"=============================================")
|
||||
self.logger.debug(f"{i}번째 옵션 checkbox_state : {checkbox_state}")
|
||||
self.logger.debug(f"=============================================")
|
||||
|
||||
if image_element:
|
||||
self.option_info['images'][original_name] = await image_element.get_attribute('src')
|
||||
if price_element:
|
||||
|
|
@ -531,23 +581,19 @@ class OptionHandler:
|
|||
for i, name in enumerate(self.option_info['original_names'].values()):
|
||||
checkbox_selector = self.checkbox_selector_template.format(index=i+1)
|
||||
checkbox_element = await self.page.query_selector(checkbox_selector)
|
||||
is_checked = self.option_info['checked_states'].get(name, False)
|
||||
# is_checked = self.option_info['checked_states'].get(name, False)
|
||||
|
||||
# 디버깅 로그: 현재 옵션 이름과 필터링된 옵션 이름 확인
|
||||
self.logger.debug(f"옵션 이름: {name}, 필터링된 옵션에 포함 여부: {name in filtered_option_names}, 현재 체크 상태: {is_checked}")
|
||||
self.logger.debug(f"옵션 이름: {name}, 필터링된 옵션에 포함 여부: {name in filtered_option_names}")
|
||||
|
||||
if checkbox_element:
|
||||
# 필터링된 이름에 포함되는 경우
|
||||
if name in filtered_option_names:
|
||||
# 체크되어 있지 않으면 체크 수행
|
||||
if not is_checked:
|
||||
await checkbox_element.click()
|
||||
# await checkbox_element.click()
|
||||
self.logger.debug(f"옵션 '{name}' 체크함")
|
||||
self.option_info['checked_states'][name] = True
|
||||
# 필터링된 이름에 포함되지 않는 경우
|
||||
else:
|
||||
# 체크되어 있으면 체크 해제 수행
|
||||
if is_checked:
|
||||
await checkbox_element.click()
|
||||
self.logger.debug(f"옵션 '{name}' 체크 해제함")
|
||||
self.option_info['checked_states'][name] = False
|
||||
|
|
|
|||
Loading…
Reference in New Issue