forked from ckh08045/AutoPercenty
145 lines
7.1 KiB
Python
145 lines
7.1 KiB
Python
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
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
|
|
from edit.price_cal import calculate_margin_and_price
|
|
|
|
# from ai.compare import find_most_similar_image_by_one
|
|
import logging
|
|
|
|
# 로거 인스턴스 가져오기
|
|
logger = logging.getLogger('default_logger')
|
|
|
|
def modify_price_page(driver, product_infos):
|
|
|
|
# 가격 탭으로 이동
|
|
logger.debug("가격탭으로 이동")
|
|
option_tab_XPATH = "//div[@id='rc-tabs-0-tab-3']"
|
|
keyword_tab_CSS = ".ant-tabs-tab:nth-child(3)"
|
|
click_element(driver, 'CSS_SELECTOR', keyword_tab_CSS, 10, 'js')
|
|
logger.debug("가격탭으로 이동 완료")
|
|
|
|
logger.debug("페이지 로딩 대기")
|
|
|
|
time.sleep(2) # 페이지 로딩 대기.
|
|
option_high_price = product_infos.option_high_price
|
|
option_low_price = product_infos.option_low_price
|
|
|
|
# tao_high_price = product_infos.tao_high_price # 디버깅을 위해 선택된 옵션가격이 아닌 기존의 원래가격을 가져옴
|
|
# tao_low_price = product_infos.tao_low_price # 디버깅을 위해 선택된 옵션가격이 아닌 기존의 원래가격을 가져옴
|
|
|
|
naver_low_price = product_infos.naver_low_price
|
|
naver_avg_price = product_infos.naver_avg_price
|
|
naver_high_price = product_infos.naver_high_price
|
|
w_delv_fee = product_infos.w_delv_fee
|
|
packing_fee = product_infos.packing_fee
|
|
|
|
inputs = {
|
|
"option_low_price": option_low_price,
|
|
"option_high_price": option_high_price,
|
|
"delv_fee": w_delv_fee,
|
|
"packing_fee": packing_fee,
|
|
"ns_low_price": naver_low_price,
|
|
"ns_high_price": naver_high_price
|
|
}
|
|
logger.debug(f"가격계산 INPUT 요소 : {inputs}")
|
|
|
|
|
|
outputs = calculate_margin_and_price(inputs)
|
|
logger.debug(f"가격계산 OUTPUT 요소 : {outputs}")
|
|
|
|
selling_price = outputs["selling_price"]
|
|
final_margin_rate = outputs["final_margin_rate"]
|
|
seller_cost = outputs["seller_cost"]
|
|
plus_margin = outputs["plus_margin"]
|
|
ns_avg_price = outputs["ns_avg_price"]
|
|
|
|
return_fee = selling_price/2
|
|
|
|
init_delv_fee = seller_cost
|
|
exchange_fee = return_fee + init_delv_fee
|
|
|
|
product_infos.plus_fee = plus_margin
|
|
product_infos.return_fee = return_fee
|
|
product_infos.init_delv_fee = init_delv_fee
|
|
product_infos.exchange_fee = exchange_fee
|
|
|
|
print(f"결정된 상품가격: {selling_price}원, 최종 마진율: {final_margin_rate:.2f}%")
|
|
print(f"판매자 원가: {seller_cost}원")
|
|
print(f"더하기 마진: {plus_margin}원")
|
|
print(f"네이버 평균가: {ns_avg_price}원")
|
|
|
|
|
|
|
|
# 가격 탭으로 이동
|
|
logger.debug("내부함수 가격 탭으로 이동")
|
|
thumb_tab_CSS = '.ant-tabs-tab:nth-child(3)'
|
|
click_element(driver, 'CSS_SELECTOR', thumb_tab_CSS, 10, 'js')
|
|
logger.debug("내부함수 가격 탭으로 이동 완료")
|
|
logger.debug("페이지 로딩 대기")
|
|
time.sleep(2) # 페이지 로딩 대기.
|
|
|
|
logger.debug("더하기마진 수정")
|
|
plus_fee_xpath="//div[@id='productMainContentContainerId']/div/div/div/div/div[2]/div/div/div[8]/div/div/div[3]/div/div/div/div/div[2]/input"
|
|
plus_fee_element = return_element(driver, 'XPATH', plus_fee_xpath, 10)
|
|
plus_fee_element.send_keys(Keys.CLEAR) # 기존 가격 삭제
|
|
driver.execute_script("arguments[0].value = '';", plus_fee_element) # 기존 가격 삭제 JS
|
|
logger.debug("기존가격 삭제")
|
|
plus_fee_element.send_keys(plus_margin) # 새 가격 입력
|
|
logger.debug(f"더하기마진 수정 완료 : {plus_margin}")
|
|
|
|
logger.debug("해외배송비 수정")
|
|
fore_delv_fee_xpath="//div[@id='productMainContentContainerId']/div/div/div/div/div[2]/div/div/div[10]/div/div/div/div/div[2]/input"
|
|
fore_delv_fee_element = return_element(driver, 'XPATH', fore_delv_fee_xpath, 10)
|
|
fore_delv_fee_element.send_keys(Keys.CLEAR) # 기존 가격 삭제
|
|
driver.execute_script("arguments[0].value = '';", fore_delv_fee_element) # 기존 가격 삭제 JS
|
|
logger.debug("기존가격 삭제")
|
|
fore_delv_fee_element.send_keys(w_delv_fee) # 새 가격 입력
|
|
logger.debug(f"해외배송비 수정 완료 : {w_delv_fee}")
|
|
|
|
logger.debug("반품비 수정")
|
|
return_fee_xpath = "//div[@id='productMainContentContainerId']/div/div/div/div/div[4]/div/div/div[3]/div/div/div/div/div[2]/input"
|
|
return_fee_element = return_element(driver, 'XPATH', return_fee_xpath, 10)
|
|
return_fee_element.send_keys(Keys.CLEAR) # 기존 가격 삭제
|
|
driver.execute_script("arguments[0].value = '';", return_fee_element) # 기존 가격 삭제 JS
|
|
logger.debug("기존가격 삭제")
|
|
return_fee_element.send_keys(return_fee) # 새 가격 입력
|
|
logger.debug(f"반품비 수정 완료 : {return_fee}")
|
|
|
|
logger.debug("초도배송비 수정")
|
|
first_delv_fee_xpath = "//div[@id='productMainContentContainerId']/div/div/div/div/div[4]/div/div/div[4]/div/div[2]/div/div/div[2]/input"
|
|
first_delv_fee_element = return_element(driver, 'XPATH', first_delv_fee_xpath, 10)
|
|
first_delv_fee_element.send_keys(Keys.CLEAR) # 기존 가격 삭제
|
|
driver.execute_script("arguments[0].value = '';", first_delv_fee_element) # 기존 가격 삭제 JS
|
|
logger.debug("기존가격 삭제")
|
|
first_delv_fee_element.send_keys(init_delv_fee) # 새 가격 입력
|
|
logger.debug(f"초도배송비 수정 완료 : {init_delv_fee}")
|
|
|
|
logger.debug("교환비 수정")
|
|
exchange_fee_xpath = "//div[@id='productMainContentContainerId']/div/div/div/div/div[4]/div/div/div[5]/div/div/div/div/div[2]/input"
|
|
exchange_fee_element = return_element(driver, 'XPATH', exchange_fee_xpath, 10)
|
|
exchange_fee_element.send_keys(Keys.CLEAR) # 기존 가격 삭제
|
|
driver.execute_script("arguments[0].value = '';", exchange_fee_element) # 기존 가격 삭제 JS
|
|
logger.debug("기존가격 삭제")
|
|
exchange_fee_element.send_keys(exchange_fee) # 새 가격 입력
|
|
logger.debug(f"교환비 수정 완료 : {exchange_fee}")
|
|
|
|
# logger.debug("기본마진율 수정")
|
|
# earning_rate_xpath = "//div[@id='productMainContentContainerId']/div/div/div/div/div[2]/div/div/div[8]/div/div/div/div/div/div/div/div[2]/input"
|
|
# earning_rate_element = return_element(driver, 'XPATH', earning_rate_xpath, 10, 'js')
|
|
# earning_rate_element.send_keys(Keys.CLEAR) # 기존 가격 삭제
|
|
# driver.execute_script("arguments[0].value = '';", earning_rate_element) # 기존 가격 삭제 JS
|
|
# earning_rate_element.send_keys('new_Price') # 새 가격 입력
|
|
|
|
|
|
# background: rgb(240, 240, 240); box-shadow: none; color: rgba(0, 0, 0, 0.85);
|
|
# 백그라운드 컬러로 빨간 가격탭 찾기
|
|
# background: rgb(255, 77, 79); box-shadow: none; color: rgb(255, 255, 255);
|
|
|
|
save_xpath="//button[contains(.,'저장하기')]"
|
|
click_element(driver, 'XPATH', save_xpath, 10)
|
|
logger.debug("옵션 정리 후 저장버튼 클릭 완료")
|