forked from ckh08045/AutoPercenty
심플모드에 대한 처리 반영
This commit is contained in:
parent
b3d1a2b934
commit
e9246a18dd
189
edit/detail1.py
189
edit/detail1.py
|
|
@ -372,7 +372,8 @@ def create_product_card(product_name, image_url, price, rank, purchase, review):
|
|||
# return product_info_md
|
||||
|
||||
def modify_detail_page(driver, product_info, gemini, translator, delv_collection, json_naver_codes, login_info):
|
||||
|
||||
simpleMode = login_info['whether_simpleMode']
|
||||
|
||||
detail_css = ".ant-tabs-tab:nth-child(6)"
|
||||
|
||||
thumb_data_note = "5"
|
||||
|
|
@ -399,32 +400,32 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
|
|||
naver_code = ""
|
||||
|
||||
|
||||
|
||||
try:
|
||||
logger.debug("네이버쇼핑 파싱 중")
|
||||
products = parse_naver_shopping(product_keyword, naver_code, isOverseas=1, sortcount=5)
|
||||
logger.debug("네이버쇼핑 파싱 완료")
|
||||
# logger.debug(f"네이버 파싱된 상품 리스트 \n {products}")
|
||||
product_info.naver_products = products
|
||||
|
||||
# 네이버 상품가격 담기
|
||||
naver_price = naver_prices(products)
|
||||
if not simpleMode: # 심플모드일 경우 네이버 파싱 패스
|
||||
try:
|
||||
logger.debug("네이버쇼핑 파싱 중")
|
||||
products = parse_naver_shopping(product_keyword, naver_code, isOverseas=1, sortcount=5)
|
||||
logger.debug("네이버쇼핑 파싱 완료")
|
||||
# logger.debug(f"네이버 파싱된 상품 리스트 \n {products}")
|
||||
product_info.naver_products = products
|
||||
|
||||
# 네이버 상품가격 담기
|
||||
naver_price = naver_prices(products)
|
||||
|
||||
if naver_price[0]: # 리턴값이 있는 경우 사용
|
||||
product_info.naver_low_price = naver_price[0]
|
||||
product_info.naver_avg_price = naver_price[1]
|
||||
product_info.naver_high_price = naver_price[2]
|
||||
else: # 리턴값이 None인 경우 기본값인 100원 사용
|
||||
product_info.naver_low_price = 100
|
||||
product_info.naver_avg_price = 100
|
||||
product_info.naver_high_price = 100
|
||||
if naver_price[0]: # 리턴값이 있는 경우 사용
|
||||
product_info.naver_low_price = naver_price[0]
|
||||
product_info.naver_avg_price = naver_price[1]
|
||||
product_info.naver_high_price = naver_price[2]
|
||||
else: # 리턴값이 None인 경우 기본값인 100원 사용
|
||||
product_info.naver_low_price = 100
|
||||
product_info.naver_avg_price = 100
|
||||
product_info.naver_high_price = 100
|
||||
|
||||
# product_info_text = NS_info(products)
|
||||
product_info_card = NS_info_with_HTML(products)
|
||||
# logger.debug(f"수집된 정보 \n {product_info_card} \n")
|
||||
logger.debug("네이버쇼핑 파싱 완료")
|
||||
except Exception as e:
|
||||
logger.debug(f"네이버쇼핑 파싱 중 에러발생 : {e}", exc_info=True)
|
||||
# product_info_text = NS_info(products)
|
||||
product_info_card = NS_info_with_HTML(products)
|
||||
# logger.debug(f"수집된 정보 \n {product_info_card} \n")
|
||||
logger.debug("네이버쇼핑 파싱 완료")
|
||||
except Exception as e:
|
||||
logger.debug(f"네이버쇼핑 파싱 중 에러발생 : {e}", exc_info=True)
|
||||
|
||||
|
||||
|
||||
|
|
@ -461,74 +462,70 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
|
|||
logger.debug(f"상세페이지 xpath 요소 가져오기 오류 발생: 요소를 찾을 수 없습니다. : {e}", exc_info=True)
|
||||
# detail_content = driver.find_element(By.XPATH, "//div[@id='productMainContentContainerId']/div/div/div[2]/div[2]/div[2]/div")
|
||||
# detail_content = driver.find_element(By.ID, "rc-tabs-0-tab-5")
|
||||
if not simpleMode: # 심플모드일 경우 AI처리 하지않음
|
||||
try:
|
||||
ActionChains(driver).move_to_element(detail_content).click().perform()
|
||||
time.sleep(1)
|
||||
logger.debug("AI 이미지 처리중")
|
||||
# contents = bard_img(image_src)
|
||||
# contents = gemini.generate_description(image_src, product_title)
|
||||
aicontents = safe_generate_content(gemini, product_info)
|
||||
logger.debug(f"{aicontents}")
|
||||
product_info.ai_contents = aicontents
|
||||
logger.debug("AI 이미지 처리 완료")
|
||||
|
||||
weight = extract_weight(aicontents)
|
||||
logger.debug(f"무게 추정 : {weight}")
|
||||
product_info.weight = weight
|
||||
|
||||
try:
|
||||
ActionChains(driver).move_to_element(detail_content).click().perform()
|
||||
time.sleep(1)
|
||||
logger.debug("AI 이미지 처리중")
|
||||
# contents = bard_img(image_src)
|
||||
# contents = gemini.generate_description(image_src, product_title)
|
||||
aicontents = safe_generate_content(gemini, product_info)
|
||||
logger.debug(f"{aicontents}")
|
||||
product_info.ai_contents = aicontents
|
||||
logger.debug("AI 이미지 처리 완료")
|
||||
|
||||
weight = extract_weight(aicontents)
|
||||
logger.debug(f"무게 추정 : {weight}")
|
||||
product_info.weight = weight
|
||||
delv_fee = find_delivery_fee(weight, delv_collection)
|
||||
logger.debug(f"무게배송비 추정 : {delv_fee}")
|
||||
product_info.w_delv_fee = delv_fee
|
||||
|
||||
packing_fee = 0 # 추가포장비의 경우 크기와 소재에 따라 래핑, 우드포장등 세분화 필요. 기본은 0
|
||||
logger.debug(f"추가포장비 추정 : {packing_fee}")
|
||||
product_info.packing_fee = packing_fee
|
||||
|
||||
delv_fee = find_delivery_fee(weight, delv_collection)
|
||||
logger.debug(f"무게배송비 추정 : {delv_fee}")
|
||||
product_info.w_delv_fee = delv_fee
|
||||
|
||||
packing_fee = 0 # 추가포장비의 경우 크기와 소재에 따라 래핑, 우드포장등 세분화 필요. 기본은 0
|
||||
logger.debug(f"추가포장비 추정 : {packing_fee}")
|
||||
product_info.packing_fee = packing_fee
|
||||
except Exception as e:
|
||||
logger.debug(f"상세페이지 편집 중 에러발생 : {e}", exc_info=True)
|
||||
|
||||
if not simpleMode: # 심플모드일 경우 가격계산 패스
|
||||
try:
|
||||
# 가격 정보 계산
|
||||
low_cost, low_margin = selling_price(product_low_cost, delv_fee, 0.29)
|
||||
high_cost, high_margin = selling_price(product_high_cost, delv_fee, 0.29)
|
||||
low_delv_fee = avg_price - low_cost
|
||||
high_delv_fee = avg_price - high_cost
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"상세페이지 편집 중 에러발생 : {e}", exc_info=True)
|
||||
|
||||
# 마진율 계산
|
||||
low_margin_r = round((low_margin / low_cost) * 100, 2)
|
||||
high_margin_r = round((high_margin / high_cost) * 100, 2)
|
||||
|
||||
try:
|
||||
# 가격 정보 계산
|
||||
low_cost, low_margin = selling_price(product_low_cost, delv_fee, 0.29)
|
||||
high_cost, high_margin = selling_price(product_high_cost, delv_fee, 0.29)
|
||||
low_delv_fee = avg_price - low_cost
|
||||
high_delv_fee = avg_price - high_cost
|
||||
|
||||
# 마진율 계산
|
||||
low_margin_r = round((low_margin / low_cost) * 100, 2)
|
||||
high_margin_r = round((high_margin / high_cost) * 100, 2)
|
||||
|
||||
# 텍스트 조합
|
||||
cost_add_text = f"""
|
||||
<h1>==== 가격과 마진율 ====</h1><br>
|
||||
해당 제품의 네이버 평균가격은 <span style="font-size:16px;"><strong><u>{avg_price:,.0f}</u></strong></span>원입니다.<br>
|
||||
해당 제품의 무게배송비는 <span style="font-size:16px;"><strong><u>{delv_fee:,.0f}</u></strong></span>원입니다.<br>
|
||||
|
||||
**마진율 확보를 위한 판매가 범위:** {low_cost:,.0f}원 ~ {high_cost:,.0f}원<br>
|
||||
|
||||
<h3>**저가 중심 계산:**</h3><br>
|
||||
* 무게 배송비 대비: {low_delv_fee:,.0f}원 {('낮은' if low_delv_fee < 0 else '높은')} 편<br>
|
||||
* 마진율: {low_margin_r:,.2f}%<br>
|
||||
<h3>**고가중심 계산:**</h3><br>
|
||||
* 무게 배송비 대비: {high_delv_fee:,.0f}원 {('낮은' if high_delv_fee < 0 else '높은')} 편<br>
|
||||
* 마진율: {high_margin_r:,.2f}%<br>
|
||||
|
||||
<h3>**추가 정보:**</h3><br>
|
||||
<h2>* 해당 제품의 파손 여부 및 무게 오차를 고려하여 더하기 마진을 설정하세요.</h2><br>
|
||||
<h3>=======================================</h3><br><br>
|
||||
"""
|
||||
|
||||
# time.sleep(2)
|
||||
# detail_content.send_keys(cost_add_text)
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"가격정보 생성 중 에러 : {e}", exc_info=True)
|
||||
# 텍스트 조합
|
||||
cost_add_text = f"""
|
||||
<h1>==== 가격과 마진율 ====</h1><br>
|
||||
해당 제품의 네이버 평균가격은 <span style="font-size:16px;"><strong><u>{avg_price:,.0f}</u></strong></span>원입니다.<br>
|
||||
해당 제품의 무게배송비는 <span style="font-size:16px;"><strong><u>{delv_fee:,.0f}</u></strong></span>원입니다.<br>
|
||||
|
||||
**마진율 확보를 위한 판매가 범위:** {low_cost:,.0f}원 ~ {high_cost:,.0f}원<br>
|
||||
|
||||
<h3>**저가 중심 계산:**</h3><br>
|
||||
* 무게 배송비 대비: {low_delv_fee:,.0f}원 {('낮은' if low_delv_fee < 0 else '높은')} 편<br>
|
||||
* 마진율: {low_margin_r:,.2f}%<br>
|
||||
<h3>**고가중심 계산:**</h3><br>
|
||||
* 무게 배송비 대비: {high_delv_fee:,.0f}원 {('낮은' if high_delv_fee < 0 else '높은')} 편<br>
|
||||
* 마진율: {high_margin_r:,.2f}%<br>
|
||||
|
||||
<h3>**추가 정보:**</h3><br>
|
||||
<h2>* 해당 제품의 파손 여부 및 무게 오차를 고려하여 더하기 마진을 설정하세요.</h2><br>
|
||||
<h3>=======================================</h3><br><br>
|
||||
"""
|
||||
|
||||
# time.sleep(2)
|
||||
# detail_content.send_keys(cost_add_text)
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"가격정보 생성 중 에러 : {e}", exc_info=True)
|
||||
|
||||
|
||||
try:
|
||||
|
|
@ -547,7 +544,7 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
|
|||
except Exception as e:
|
||||
logger.debug(f"HTML 수정 버튼 요소를 찾을 수 없습니다. : {e}", exc_info=True)
|
||||
|
||||
|
||||
|
||||
# html_btn = driver.find_element(By.CSS_SELECTOR, ".ck-source-editing-button")
|
||||
|
||||
|
||||
|
|
@ -582,18 +579,18 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
|
|||
logger.debug(f"원본 이미지 URLs [{len(detail_images)}]개 수집 완료")
|
||||
logger.debug(f"detail_images List : {detail_images}")
|
||||
# logger.debug(f"현재 속성값 :{current_value}")
|
||||
if not simpleMode: # 심플모드일 경우 상품카드 작성하지 않음
|
||||
logger.debug("product_info_card 결합.")
|
||||
info_value = product_info_card + '<br><br>' + cost_add_text + '<br><br>'
|
||||
# textarea.send_keys(product_info_card)
|
||||
time.sleep(0.2)
|
||||
combined_value = info_value
|
||||
|
||||
logger.debug("product_info_card 결합.")
|
||||
info_value = product_info_card + '<br><br>' + cost_add_text + '<br><br>'
|
||||
# textarea.send_keys(product_info_card)
|
||||
time.sleep(0.2)
|
||||
combined_value = info_value
|
||||
logger.debug(f"{combined_value}")
|
||||
|
||||
logger.debug(f"{combined_value}")
|
||||
|
||||
# # data-value 속성을 새로운 값으로 설정합니다.
|
||||
logger.debug("product_info_card + 기존 내용 입력.")
|
||||
driver.execute_script("arguments[0].setAttribute('data-value', arguments[1]);", textarea, combined_value)
|
||||
# # data-value 속성을 새로운 값으로 설정합니다.
|
||||
logger.debug("product_info_card + 기존 내용 입력.")
|
||||
driver.execute_script("arguments[0].setAttribute('data-value', arguments[1]);", textarea, combined_value)
|
||||
|
||||
logger.debug("HTML 수정 버튼 다시 클릭하여 기본편집페이지로 돌아감.")
|
||||
click_element(driver, 'XPATH', html_btn_xpath, 5, 'ac')
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ import logging
|
|||
# 로거 인스턴스 가져오기
|
||||
logger = logging.getLogger('default_logger')
|
||||
|
||||
def modify_option_page(driver, product_info, translator):
|
||||
|
||||
def modify_option_page(driver, product_info, translator, login_info):
|
||||
simpleMode = login_info['whether_simpleMode']
|
||||
|
||||
option_css = ".ant-tabs-tab:nth-child(2)"
|
||||
|
||||
thumb_data_note = "1"
|
||||
|
|
@ -151,7 +152,8 @@ def modify_option_page(driver, product_info, translator):
|
|||
logger.debug("가격 낮은 순으로 정렬")
|
||||
low_price_order_xpath = f"//div[{option_idx}]/div/div/div[2]/div/div/div[4]/div[2]/div[2]/div/div[4]/button"
|
||||
click_element(driver, 'XPATH', low_price_order_xpath, 10, 'js')
|
||||
edit_option(driver, option_idx, options_info[f'option_type_{option_idx}']['options_count']) # 각 옵션의 전체 체크박스 해제
|
||||
if not simpleMode: # 심플모드일 경우 옵션 편집하지 않음. 옵션 번역만.
|
||||
edit_option(driver, option_idx, options_info[f'option_type_{option_idx}']['options_count']) # 각 옵션의 전체 체크박스 해제
|
||||
# 가격 낮은 순으로 재정렬
|
||||
logger.debug("가격 낮은 순으로 재정렬")
|
||||
click_element(driver, 'XPATH', low_price_order_xpath, 10, 'js')
|
||||
|
|
@ -171,8 +173,9 @@ def modify_option_page(driver, product_info, translator):
|
|||
# A-Z
|
||||
# xpath=//span[contains(.,'A-Z')]
|
||||
AtoZ_xpath="//div[@id='productMainContentContainerId']/div/div[2]/div/div/div[2]/div/div/div/div/div[2]/div/div/div[4]/div/div/div/div/button/span"
|
||||
click_element(driver, 'XPATH', AtoZ_xpath, 10, 'normal')
|
||||
|
||||
if not simpleMode: # 심플모드일 경우 옵션 AtoZ 편집하지 않음. 옵션 번역만.
|
||||
click_element(driver, 'XPATH', AtoZ_xpath, 10, 'normal')
|
||||
|
||||
# 1-99
|
||||
# xpath=//span[contains(.,'1-99')]
|
||||
# xpath=//div[@id='productMainContentContainerId']/div/div[2]/div/div/div[2]/div/div/div/div/div[2]/div/div/div[4]/div/div/div/div[2]/button/span
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import logging
|
|||
# 로거 인스턴스 가져오기
|
||||
logger = logging.getLogger('default_logger')
|
||||
|
||||
def modify_product_title(driver, product_infos):
|
||||
def modify_product_title(driver, product_infos, login_info):
|
||||
|
||||
thumb_data_note = "0"
|
||||
click_and_confirm_tab(driver, thumb_data_note, 10)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ class LoginWidget(QtWidgets.QWidget):
|
|||
self.whether_modifyProductDetail = True
|
||||
self.whether_modifyImageTanslation = False
|
||||
self.whether_uploadToMarket = False
|
||||
self.whether_simpleMode = False
|
||||
|
||||
|
||||
self.check_for_updates(self.login_db, self.CURRENT_VERSION)
|
||||
|
|
@ -197,6 +198,13 @@ class LoginWidget(QtWidgets.QWidget):
|
|||
self.uploadToMarketSwitch.clicked.connect(self.uploadToMarket)
|
||||
self.uploadToMarketSwitch_layout = self.create_label_and_switch("마켓 업로드", self.uploadToMarketSwitch)
|
||||
|
||||
|
||||
self.simpleModeSwitch = ToggleSwitch(self)
|
||||
self.simpleModeSwitch.move(10, 90)
|
||||
self.simpleModeSwitch.setChecked(False) # 기본 상태는 OFF
|
||||
self.simpleModeSwitch.clicked.connect(self.SimpleMode)
|
||||
self.simpleModeSwitch_Layout = self.create_label_and_switch("심플 모드", self.simpleModeSwitch)
|
||||
|
||||
self.infoLabel4 = QtWidgets.QLabel(" 퍼센티 자동화 by 리앤수Int.")
|
||||
|
||||
|
||||
|
|
@ -223,6 +231,7 @@ class LoginWidget(QtWidgets.QWidget):
|
|||
# for i, label_text in enumerate(labels, start = 1):
|
||||
# label = QtWidgets.QLabel(label_text)
|
||||
# setting_layout.addWidget(label) # 설명 라벨은 2열(인덱스 1)에 배치
|
||||
setting_layout.addLayout(self.simpleModeSwitch_Layout)
|
||||
|
||||
setting_layout.addLayout(self.modifyProductTagSwitch_layout)
|
||||
setting_layout.addLayout(self.modifyProductThumbSwitch_layout)
|
||||
|
|
@ -328,6 +337,15 @@ class LoginWidget(QtWidgets.QWidget):
|
|||
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
||||
|
||||
|
||||
|
||||
def simpleMode(self, checked):
|
||||
if checked:
|
||||
self.whether_simpleMode = True
|
||||
else:
|
||||
self.whether_simpleMode = False
|
||||
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
||||
|
||||
|
||||
def togglePasswordVisibility(self):
|
||||
if self.showPasswordCheckBox.isChecked():
|
||||
self.passwordInput.setEchoMode(QtWidgets.QLineEdit.Normal)
|
||||
|
|
|
|||
1
main.py
1
main.py
|
|
@ -128,6 +128,7 @@ def DB_setting():
|
|||
"whether_modifyProductDetail": login_widget.whether_modifyProductDetail,
|
||||
"whether_modifyImageTanslation": login_widget.whether_modifyImageTanslation,
|
||||
"whether_uploadToMarket": login_widget.whether_uploadToMarket,
|
||||
"whether_simpleMode": login_widget.whether_simpleMode,
|
||||
"login_result": login_widget.result,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ def modify_products(driver, gemini, translator, mongo_config, login_info, set_nu
|
|||
|
||||
autoPercentyProductsDB.reset_product_by_id('660d636271e50111cf71284e')
|
||||
autoPercentyProductsDB.reset_product_by_id('660d635371e50111cf712842')
|
||||
|
||||
|
||||
try:
|
||||
if login_info['per_mode']:
|
||||
current_user = login_info['per_email']
|
||||
|
|
@ -192,15 +192,16 @@ def modify_products(driver, gemini, translator, mongo_config, login_info, set_nu
|
|||
'title_modification': login_info["whether_modifyProductName"],
|
||||
# 'trans_detailImage': login_info["whether_modifyImageTanslation"],
|
||||
'upload_to_market': login_info["whether_uploadToMarket"],
|
||||
'simpleMode': login_info["whether_simpleMode"],
|
||||
}
|
||||
|
||||
steps_and_actions = [
|
||||
('tag_modification', edit_tag, (driver, product_infos[i-1])),
|
||||
('thumbnail_modification', modify_thumb_page, (driver, product_infos[i-1])),
|
||||
('option_modification', modify_option_page, (driver, product_infos[i-1], translator)),
|
||||
('option_modification', modify_option_page, (driver, product_infos[i-1], translator, login_info)),
|
||||
('detail_page_modification', modify_detail_page, (driver, product_infos[i-1], gemini, translator, delv_collection, json_naver_codes, login_info)),
|
||||
('price_modification', modify_price_page, (driver, product_infos[i-1])),
|
||||
('title_modification', modify_product_title, (driver, product_infos[i-1])),
|
||||
('title_modification', modify_product_title, (driver, product_infos[i-1], login_info)),
|
||||
# ('trans_detailImage', tran_detail_image, (driver, product_infos[i-1])),
|
||||
('upload_to_market', upload_to_market, (driver, product_infos[i-1])),
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in New Issue