ai 마크다운 제일마지막으로 이동

produc_info 항목 수정
gemini return 값 수정
This commit is contained in:
Envy_PC 2024-04-23 20:44:08 +09:00
parent 305b21798d
commit 60bd86a898
3 changed files with 160 additions and 89 deletions

View File

@ -189,7 +189,7 @@ class ImageDescriptionGenerator:
logger.debug(f"response.text : {response.text}")
response_html = markdown.markdown(response.text)
logger.debug(f"response_html : {response_html}")
return response_html
return response_html, response.text
else:
# 후보 결과가 없거나 유효하지 않을 경우 기본 응답 반환

View File

@ -22,6 +22,62 @@ logger = logging.getLogger('default_logger')
avg_price = 0
def detail_ai(driver, detail_content, aicontents):
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)
# contents 변수의 값이 None이 아닐 때만 send_keys 메서드를 호출합니다.
if aicontents[0] is not None:
logger.debug("aicontents[0] 입력시작")
# html_insert_btn_xpath="//div[@id='productMainContentContainerId']/div/div/div[2]/div[2]/div/div[1]/div[2]/div/div/button[7]"
# click_element(driver, 'XPATH', html_insert_btn_xpath, 5, 'ac')
# logger.debug("html_insert_btn_xpath 클릭")
detail_content.send_keys(aicontents[0])
# logger.debug("html 요소로 전송")
# html_insert_ok_xpath="//div[@id='productMainContentContainerId']/div/div[2]/div[2]/div[2]/div/div[1]/div[2]/div/button[1]"
# click_element(driver, 'XPATH', html_insert_ok_xpath, 5, 'ac')
# logger.debug("html_insert_ok_xpath 클릭")
logger.debug(f"AI 컨텐츠 입력완료")
detail_content.send_keys(Keys.ENTER)
else:
# contents 변수가 None일 때의 대체 처리
# 예: detail_content.send_keys("") 또는 아무 동작도 수행하지 않음
pass
except Exception as e:
logger.debug(f"AI 컨텐츠 수정 중 에러발생 : {e}", exc_info=True)
def detail_html(driver):
try:
logger.debug("HTML 수정 버튼 클릭 .")
html_btn_by_contains_xpath="//button[contains(.,'소스')]"
html_btn_css = "ck.ck-button.ck-source-editing-button.ck-off.ck-button_with-text"
html_btn_xpath="//div[@id='productMainContentContainerId']/div/div/div[2]/div[2]/div/div/div[2]/div/div/button[8]"
click_element(driver, 'XPATH', html_btn_xpath, 5, 'ac')
# html_btn = WebDriverWait(driver, 10).until(
# # EC.presence_of_element_located((By.CSS_SELECTOR, ".ck-source-editing-button"))
# EC.presence_of_element_located(By.CLASS_NAME, html_btn_xpath)
# # EC.presence_of_element_located((By.CSS_SELECTOR, "button.ck.ck-button.ck-source-editing-button.ck-off.ck-button_with-text"))
# )
# logger.debug("HTML 수정 버튼을 성공적으로 찾았습니다.")
# html_btn.click()
except Exception as e:
logger.debug(f"HTML 수정 버튼 요소를 찾을 수 없습니다. : {e}", exc_info=True)
def detail_textarea(driver):
try:
# textarea_css = "ck-source-editing-area"
@ -463,69 +519,70 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
# 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_html = aicontents[0]
product_info.ai_contents_mark = aicontents[1]
logger.debug("AI 이미지 처리 완료")
weight = extract_weight(aicontents[0])
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)
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
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)
# 마진율 계산
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>
# 텍스트 조합
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>
**마진율 확보를 위한 판매가 범위:** {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>
* 무게 배송비 대비: {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)
<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)
except Exception as e:
logger.debug(f"가격정보 생성 중 에러 : {e}", exc_info=True)
try:
@ -547,7 +604,6 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
# html_btn = driver.find_element(By.CSS_SELECTOR, ".ck-source-editing-button")
try:
# textarea_css = "ck-source-editing-area"
# click_element(driver, 'CSS_SELECTOR', textarea_css, 10, 'js')
@ -599,37 +655,42 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
except Exception as e:
logger.debug(f"product_info_card 수정 중 에러발생 : {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)
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)
# contents 변수의 값이 None이 아닐 때만 send_keys 메서드를 호출합니다.
if aicontents is not None:
html_insert_btn_xpath="//div[@id='productMainContentContainerId']/div/div/div[2]/div[2]/div/div/div[2]/div/div/button[7]"
click_element(driver, 'XPATH', html_insert_btn_xpath, 5, 'ac')
detail_content.send_keys(aicontents)
html_insert_ok_xpath="/html/body/div[6]/div/div[3]/div/div[2]/div[1]/div/div/div[2]/div[2]/div[2]/div/div[1]/div[2]/div/button[1]"
click_element(driver, 'XPATH', html_insert_ok_xpath, 5, 'ac')
logger.debug(f"AI 컨텐츠 입력완료")
detail_content.send_keys(Keys.DOWN)
else:
# contents 변수가 None일 때의 대체 처리
# 예: detail_content.send_keys("") 또는 아무 동작도 수행하지 않음
pass
except Exception as e:
logger.debug(f"AI 컨텐츠 수정 중 에러발생 : {e}", exc_info=True)
# # contents 변수의 값이 None이 아닐 때만 send_keys 메서드를 호출합니다.
# if aicontents[0] is not None:
# logger.debug("aicontents[0] 입력시작")
# html_insert_btn_xpath="//div[@id='productMainContentContainerId']/div/div/div[2]/div[2]/div/div[1]/div[2]/div/div/button[7]"
# click_element(driver, 'XPATH', html_insert_btn_xpath, 5, 'ac')
# logger.debug("html_insert_btn_xpath 클릭")
# detail_content.send_keys(aicontents[0])
# logger.debug("html 요소로 전송")
# html_insert_ok_xpath="//div[@id='productMainContentContainerId']/div/div[2]/div[2]/div[2]/div/div[1]/div[2]/div/button[1]"
# click_element(driver, 'XPATH', html_insert_ok_xpath, 5, 'ac')
# logger.debug("html_insert_ok_xpath 클릭")
# logger.debug(f"AI 컨텐츠 입력완료")
# detail_content.send_keys(Keys.DOWN)
# else:
# # contents 변수가 None일 때의 대체 처리
# # 예: detail_content.send_keys("") 또는 아무 동작도 수행하지 않음
# pass
# except Exception as e:
# logger.debug(f"AI 컨텐츠 수정 중 에러발생 : {e}", exc_info=True)
trans_img_tag = login_info["whether_modifyImageTanslation"]
@ -648,7 +709,7 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
try:
for i, detail_image in enumerate(detail_images):
logger.debug(f"상세페이지 {i+1}번째 이미지 번역 시작")
logger.debug(f"상세페이지 [{i+1}]/[{len(detail_images)}]번째 이미지 번역 시작")
logger.debug(f"이미지 타입 : {type(detail_image)}")
returned_img = image_trans(detail_image, translator, 'translate')
image_to_clipboard(returned_img)
@ -675,8 +736,16 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
detail_content.send_keys(Keys.DELETE)
logger.debug("====번역이미지 붙여넣기 완료=====")
detail_html(driver)
time.sleep(0.5)
detail_textarea(driver)
time.sleep(0.5)
detail_ai(driver,aicontents, detail_content)
time.sleep(0.5)
detail_html(driver)
time.sleep(0.5)
logger.debug("상세페이지 편집 저장")
click_element(driver, "XPATH", save_button_xpath, 5, 'js')

View File

@ -23,7 +23,8 @@ class ProductInfo:
self.return_fee = None # 반품비
self.init_delv_fee = None # 초기반품비
self.exchange_fee = None # 교환배송비
self.ai_contents = None # ai가 생성한 컨텐츠 결과
self.ai_contents_html = None # ai가 생성한 컨텐츠 결과
self.ai_contents_mark = None # ai가 생성한 컨텐츠 결과
self.current_value = None # 상세페이지의 현재 내용
self.new_value = None # 상세페이지의 바뀐 내용
@ -75,7 +76,8 @@ class ProductInfo:
'return_fee': self.return_fee,
'init_delv_fee': self.init_delv_fee,
'exchange_fee': self.exchange_fee,
'ai_contents': self.ai_contents,
'ai_contents_html': self.ai_contents_html,
'ai_contents_mark': self.ai_contents_mark,
'current_value': self.current_value,
'new_value': self.new_value,
'naver_products': self.naver_products,