modified: amazon/__pycache__/approve.cpython-39.pyc
modified: amazon/__pycache__/asin_status.cpython-39.pyc modified: amazon/__pycache__/del_brand.cpython-39.pyc modified: amazon/__pycache__/match_action.cpython-39.pyc modified: amazon/__pycache__/price_match.cpython-39.pyc modified: amazon/approve.py modified: amazon/asin_status.py modified: amazon/del_brand.py modified: amazon/match_action.py modified: amazon/price_match.py modified: main.py
This commit is contained in:
@@ -1081,7 +1081,69 @@ class ApproveTask:
|
||||
if shop_name in runing_shop:
|
||||
del runing_shop[shop_name]
|
||||
self.log(f"店铺 {shop_name} 已从执行列表中移除")
|
||||
|
||||
|
||||
def action_init(self,driver,country_name,shop_name,risk_listing_filter):
|
||||
"""切换到指定国际 -> 页面 -》 筛选好"""
|
||||
max_retries = 5
|
||||
switch_success = False
|
||||
switch_success_pg = False
|
||||
search_success = False
|
||||
sku_ls = []
|
||||
for retry in range(max_retries):
|
||||
try:
|
||||
self.log(f"尝试切换到国家 {country_name} (第 {retry + 1}/{max_retries} 次)")
|
||||
if retry > 2:
|
||||
# 刷新不行就重新打开店铺
|
||||
self.log("重试前重新打开店铺...")
|
||||
try:
|
||||
driver.close_store()
|
||||
time.sleep(3)
|
||||
driver.open_shop(shop_name)
|
||||
except Exception as e:
|
||||
self.log(f"关闭重新打开店铺: {str(e)}", "WARNING")
|
||||
# 如果不是第一次尝试,先刷新页面
|
||||
if retry > 0:
|
||||
self.log("重试前刷新页面...")
|
||||
try:
|
||||
driver.tab.refresh()
|
||||
time.sleep(3)
|
||||
except Exception as e:
|
||||
self.log(f"刷新页面失败: {str(e)}", "WARNING")
|
||||
|
||||
switch_success = driver.SwitchingCountries(country_name)
|
||||
if switch_success:
|
||||
self.log(f"成功切换到国家 {country_name}")
|
||||
|
||||
# 切换到库存管理页面
|
||||
driver.SwitchPage()
|
||||
self.log(f"已切换到库存管理页面")
|
||||
time.sleep(3)
|
||||
switch_success_pg = True
|
||||
|
||||
sku_ls = driver.search(filter_type=risk_listing_filter)
|
||||
search_success = True
|
||||
self.log(f"国家 {country_name} 搜索出 {len(sku_ls)} 商品,开始处理...")
|
||||
break
|
||||
else:
|
||||
self.log(f"切换到国家 {country_name} 失败", "WARNING")
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
self.log(f"切换国家 {country_name} 异常: {str(e)}", "ERROR")
|
||||
self.log(traceback.format_exc(), "ERROR")
|
||||
|
||||
# 如果还有重试机会,等待后继续
|
||||
if retry < max_retries - 1:
|
||||
time.sleep(2)
|
||||
|
||||
# 如果切换失败,直接返回
|
||||
# if not switch_success or not switch_success_pg or not search_success:
|
||||
# error_message = f"切换到国家({switch_success})/库存页面({switch_success_pg})/搜索筛选到指定选项({search_success}) {country_name} 失败,已重试 {max_retries} 次,跳过该国家"
|
||||
# self.log(error_message, "ERROR")
|
||||
# if task_id in runing_task:
|
||||
# runing_task[task_id]["processed_countries"] += 1
|
||||
return switch_success,switch_success_pg,search_success,sku_ls
|
||||
|
||||
def process_country(self, driver: AmzoneApprove, country_code: str, task_id: int, shop_name: str, risk_listing_filter: str):
|
||||
"""处理单个国家的审批任务
|
||||
|
||||
@@ -1108,87 +1170,98 @@ class ApproveTask:
|
||||
max_retries = 3
|
||||
switch_success = False
|
||||
|
||||
for retry in range(max_retries):
|
||||
try:
|
||||
self.log(f"尝试切换到国家 {country_name} (第 {retry + 1}/{max_retries} 次)")
|
||||
if retry > 1:
|
||||
# 刷新不行就重新打开店铺
|
||||
self.log("重试前重新打开店铺...")
|
||||
try:
|
||||
driver.close_store()
|
||||
time.sleep(3)
|
||||
driver.open_shop(shop_name)
|
||||
except Exception as e:
|
||||
self.log(f"关闭重新打开店铺: {str(e)}", "WARNING")
|
||||
|
||||
# 如果不是第一次尝试,先刷新页面
|
||||
if retry > 0:
|
||||
self.log("重试前刷新页面...")
|
||||
try:
|
||||
driver.tab.refresh()
|
||||
time.sleep(3)
|
||||
except Exception as e:
|
||||
self.log(f"刷新页面失败: {str(e)}", "WARNING")
|
||||
|
||||
switch_success = driver.SwitchingCountries(country_name)
|
||||
if switch_success:
|
||||
self.log(f"成功切换到国家 {country_name}")
|
||||
break
|
||||
else:
|
||||
self.log(f"切换到国家 {country_name} 失败", "WARNING")
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
self.log(f"切换国家 {country_name} 异常: {str(e)}", "ERROR")
|
||||
self.log(traceback.format_exc(), "ERROR")
|
||||
|
||||
# 如果还有重试机会,等待后继续
|
||||
if retry < max_retries - 1:
|
||||
time.sleep(2)
|
||||
|
||||
# for retry in range(max_retries):
|
||||
# try:
|
||||
# self.log(f"尝试切换到国家 {country_name} (第 {retry + 1}/{max_retries} 次)")
|
||||
# if retry > 1:
|
||||
# # 刷新不行就重新打开店铺
|
||||
# self.log("重试前重新打开店铺...")
|
||||
# try:
|
||||
# driver.close_store()
|
||||
# time.sleep(3)
|
||||
# driver.open_shop(shop_name)
|
||||
# except Exception as e:
|
||||
# self.log(f"关闭重新打开店铺: {str(e)}", "WARNING")
|
||||
#
|
||||
# # 如果不是第一次尝试,先刷新页面
|
||||
# if retry > 0:
|
||||
# self.log("重试前刷新页面...")
|
||||
# try:
|
||||
# driver.tab.refresh()
|
||||
# time.sleep(3)
|
||||
# except Exception as e:
|
||||
# self.log(f"刷新页面失败: {str(e)}", "WARNING")
|
||||
#
|
||||
# switch_success = driver.SwitchingCountries(country_name)
|
||||
# if switch_success:
|
||||
# self.log(f"成功切换到国家 {country_name}")
|
||||
# break
|
||||
# else:
|
||||
# self.log(f"切换到国家 {country_name} 失败", "WARNING")
|
||||
#
|
||||
# except Exception as e:
|
||||
# import traceback
|
||||
# self.log(f"切换国家 {country_name} 异常: {str(e)}", "ERROR")
|
||||
# self.log(traceback.format_exc(), "ERROR")
|
||||
#
|
||||
# # 如果还有重试机会,等待后继续
|
||||
# if retry < max_retries - 1:
|
||||
# time.sleep(2)
|
||||
#
|
||||
# # 如果切换失败,直接返回
|
||||
# if not switch_success:
|
||||
# error_message = f"切换到国家 {country_name} 失败,已重试 {max_retries} 次,跳过该国家"
|
||||
# self.log(error_message, "ERROR")
|
||||
# if task_id in runing_task:
|
||||
# runing_task[task_id]["processed_countries"] += 1
|
||||
# return
|
||||
#
|
||||
# # 切换到库存管理页面
|
||||
# try:
|
||||
# driver.SwitchPage()
|
||||
# self.log(f"已切换到库存管理页面")
|
||||
# except Exception as e:
|
||||
# import traceback
|
||||
# self.log(f"切换页面失败: {str(e)}", "ERROR")
|
||||
# self.log(traceback.format_exc(), "ERROR")
|
||||
# if task_id in runing_task:
|
||||
# runing_task[task_id]["processed_countries"] += 1
|
||||
# return
|
||||
#
|
||||
# # 搜索需要审批的商品,最多重试3次
|
||||
# sku_ls = []
|
||||
# for retry in range(max_retries):
|
||||
# try:
|
||||
# self.log(f"尝试搜索需要审批的商品 (第 {retry + 1}/{max_retries} 次)")
|
||||
# sku_ls = driver.search(filter_type=risk_listing_filter)
|
||||
# break
|
||||
# except Exception as e:
|
||||
# self.log(f"搜索商品异常: {str(e)}", "ERROR")
|
||||
# if retry < max_retries - 1:
|
||||
# try:
|
||||
# driver.tab.refresh()
|
||||
# time.sleep(3)
|
||||
# except Exception as refresh_error:
|
||||
# self.log(f"刷新页面失败: {str(refresh_error)}", "WARNING")
|
||||
#
|
||||
max_retries = 5
|
||||
switch_success, switch_success_pg, search_success,sku_ls = self.action_init(driver, country_name, shop_name,
|
||||
risk_listing_filter)
|
||||
# 如果切换失败,直接返回
|
||||
if not switch_success:
|
||||
error_message = f"切换到国家 {country_name} 失败,已重试 {max_retries} 次,跳过该国家"
|
||||
if not switch_success or not switch_success_pg or not search_success:
|
||||
error_message = f"切换到国家({switch_success})/库存页面({switch_success_pg})/搜索筛选到指定选项({search_success}) {country_name} 失败,已重试 {max_retries} 次,跳过该国家"
|
||||
self.log(error_message, "ERROR")
|
||||
if task_id in runing_task:
|
||||
runing_task[task_id]["processed_countries"] += 1
|
||||
return
|
||||
|
||||
# 切换到库存管理页面
|
||||
try:
|
||||
driver.SwitchPage()
|
||||
self.log(f"已切换到库存管理页面")
|
||||
except Exception as e:
|
||||
import traceback
|
||||
self.log(f"切换页面失败: {str(e)}", "ERROR")
|
||||
self.log(traceback.format_exc(), "ERROR")
|
||||
if task_id in runing_task:
|
||||
runing_task[task_id]["processed_countries"] += 1
|
||||
return
|
||||
|
||||
# 搜索需要审批的商品,最多重试3次
|
||||
sku_ls = []
|
||||
for retry in range(max_retries):
|
||||
try:
|
||||
self.log(f"尝试搜索需要审批的商品 (第 {retry + 1}/{max_retries} 次)")
|
||||
sku_ls = driver.search(filter_type=risk_listing_filter)
|
||||
break
|
||||
except Exception as e:
|
||||
self.log(f"搜索商品异常: {str(e)}", "ERROR")
|
||||
if retry < max_retries - 1:
|
||||
try:
|
||||
driver.tab.refresh()
|
||||
time.sleep(3)
|
||||
except Exception as refresh_error:
|
||||
self.log(f"刷新页面失败: {str(refresh_error)}", "WARNING")
|
||||
|
||||
# 如果没有需要审批的商品,直接返回
|
||||
|
||||
# # 如果没有需要审批的商品,直接返回
|
||||
if len(sku_ls) == 0:
|
||||
self.log(f"国家 {country_name} 没有需要审批的商品")
|
||||
if task_id in runing_task:
|
||||
runing_task[task_id]["processed_countries"] += 1
|
||||
return
|
||||
|
||||
|
||||
self.log(f"国家 {country_name} 有 {len(sku_ls)} 个需要审批的商品,开始处理...")
|
||||
|
||||
# 处理所有需要审批的商品(通过yield获取结果)
|
||||
|
||||
Reference in New Issue
Block a user