Commit 666eed18 authored by 邱阿朋's avatar 邱阿朋

refactor(app): 重构广告成本计算逻辑

- 移除了不必要的 HTML 解析代码
- 优化了 vendor_info 数据的生成方式,支持多国别商店 ID
- 引入了货币符号映射,简化了数据处理逻辑
- 删除了未使用的变量和注释
parent ea63062f
......@@ -10,6 +10,7 @@ from app.vc.interface import AutoInterface
from DrissionPage import ChromiumPage as Page
from datetime import datetime
class AdvertCost(AutoInterface):
def __init__(self, logger: Logger, page: Page, country: str):
self.logger = logger
......@@ -61,25 +62,27 @@ class AdvertCost(AutoInterface):
return results
def run(self,file_name: str):
def run(self, file_name: str):
self.__page_get("hz/vendor/members/advertising/home?ref_=vc_xx_subNav")
wrapper_html = self.page.ele(". columns-wrapper a20m-columns-wrapper", timeout=5).html
# wrapper_html = self.page.ele(". columns-wrapper a20m-columns-wrapper", timeout=5).html
# 解析并提取信息
vendor_info = self.__parse_vendor_info(wrapper_html)
# vendor_info = self.__parse_vendor_info(wrapper_html)
all_data = []
if self.country == "US":
# 要删除的 ID 列表
remove_store_ids = ["APTLHZWMS9DOG", "A2AZWYRRZS3OC0", "A1H6T3B2QQ0EPK"]
vendor_info = [item for item in vendor_info if item['id'] not in remove_store_ids]
# 要新增的 ID 列表
store_ids = ["A2VLKUSRNEY0D6", "A1OC20P16QN7BY", "A1YZS56TASXGM1", "A1EC618IVW7B1L"]
vendor_info = []
store_ids = {
"US": [
"A1N0INZWHQEC1X", "A1JFHJEJBHFH4W", "A1P4BWBIUQH4X6",
"A2VLKUSRNEY0D6", "A1OC20P16QN7BY", "A1YZS56TASXGM1", "A1EC618IVW7B1L"
],
"JP": ["A2S5HH4XRRCAZ0", "A2JCA95F83WKJL"],
"UK": ["AK7T8OM0L2CTO"],
"FR": ["A1LAUA4LDUDQH9"],
"DE": ["A1JJUIIUQRO63M"],
"CA": ["A3OE9R2606Z2UP"]
}
for store_id in store_ids:
vendor_info.append({'name': store_id, 'id': store_id})
if self.country == "JP":
vendor_info.append({'name': "A2JCA95F83WKJL", 'id': "A2JCA95F83WKJL"})
# 打印结果
for info in vendor_info:
......@@ -129,20 +132,20 @@ class AdvertCost(AutoInterface):
data = pd.read_excel(self.result_file_name, keep_default_na=False, na_values=[])
# 定义国家到货币符号的映射
currency_symbols = {
"US": "USD",
"UK": "GBP",
"JP": "JPY",
"FR": "EUR",
"DE": "EUR",
"CA": "CAD",
}
for _, item_row in data.iterrows():
if self.country == "US":
asin = item_row.get('Products', '').split("-")[0]
spend = item_row.get('Spend(USD)', 0.00), # 金额
elif self.country == "JP":
symbol = currency_symbols.get(self.country)
asin = item_row.get('Products', '').split("-")[0]
spend = item_row.get('Spend(JPY)', 0.00), # 金额
elif self.country == "CA":
asin = item_row.get('Products', '').split("-")[0]
spend = item_row.get('Spend(CAD)', 0.00), # 金额
else:
asin = ''
spend = 0.00
spend = item_row.get(f'Spend({symbol})', 0.00), # 金额
if asin == '' or spend == 0.00:
self.logger.warning(f"asin为空或无金额")
continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment