Commit 92b3eed8 authored by 邱阿朋's avatar 邱阿朋

refactor(vc): 重构广告费用和产品销售数据处理

-优化广告费用处理逻辑,统一处理不同国家的数据格式
- 改进产品销售数据抓取,增加对日本站点的特殊处理
- 添加国家代码到产品销售数据,提高数据准确性
parent e8a92103
...@@ -123,12 +123,13 @@ class AdvertCost(AutoInterface): ...@@ -123,12 +123,13 @@ class AdvertCost(AutoInterface):
elif self.country == "JP": elif self.country == "JP":
asin = item_row.get('商品', '').split("-")[0] asin = item_row.get('商品', '').split("-")[0]
spend = item_row.get('花费(JPY)', 0.00), # 金额 spend = item_row.get('花费(JPY)', 0.00), # 金额
if isinstance(spend, tuple):
spend = float(spend[0])
else: else:
asin = '' asin = ''
spend = 0.00 spend = 0.00
if isinstance(spend, tuple):
spend = float(spend[0])
push_data = { push_data = {
'asin': asin, # ASIN 'asin': asin, # ASIN
'spend': spend, # 金额 'spend': spend, # 金额
......
...@@ -8,7 +8,7 @@ from app.logger.logger import Logger ...@@ -8,7 +8,7 @@ from app.logger.logger import Logger
from app.vc.interface import AutoInterface from app.vc.interface import AutoInterface
from DrissionPage import ChromiumPage as Page from DrissionPage import ChromiumPage as Page
from datetime import datetime from datetime import datetime, timedelta
class ProductSales(AutoInterface): class ProductSales(AutoInterface):
...@@ -28,7 +28,18 @@ class ProductSales(AutoInterface): ...@@ -28,7 +28,18 @@ class ProductSales(AutoInterface):
self.page.get(full_url, timeout=5) self.page.get(full_url, timeout=5)
def run(self, file_name: str): def run(self, file_name: str):
self.__page_get("retail-analytics/dashboard/sales?submit=true&time-period=daily") # 获取当天日期
today = datetime.now().date()
# 计算前3天的日期
daily_day = today - timedelta(days=3)
# 默认为美国
url = "retail-analytics/dashboard/sales?submit=true&time-period=daily"
if self.country == "JP":
url = f"retail-analytics/dashboard/sales?daily-day={daily_day}&submit=true&time-period=daily"
self.__page_get(url)
self.page.ele("#raw_xlsx_btn").click() self.page.ele("#raw_xlsx_btn").click()
self.logger.debug("点击导出等待下载任务提交...") self.logger.debug("点击导出等待下载任务提交...")
self.page.wait(3) self.page.wait(3)
...@@ -64,6 +75,7 @@ class ProductSales(AutoInterface): ...@@ -64,6 +75,7 @@ class ProductSales(AutoInterface):
'asin': item_row.get('ASIN', ''), 'asin': item_row.get('ASIN', ''),
'ordered_revenue': item_row.get('Ordered Revenue', ''), # 订单金额 'ordered_revenue': item_row.get('Ordered Revenue', ''), # 订单金额
'ordered_units': item_row.get('Ordered Units', ''), # 订单数量 'ordered_units': item_row.get('Ordered Units', ''), # 订单数量
'country': self.country,
} }
# 推送数据 # 推送数据
rabbit.send_message(push_data) rabbit.send_message(push_data)
......
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