Commit 2cde7d15 by imwangxiaozhou

feat: 支持配置数据同步的时间范围

- 在配置文件中添加 data_range_days 参数,默认为 1800 天
- 修改 fetch_merchants_from_api 函数,接受动态天数参数
- 同步任务从配置读取天数,替代之前固定的 30 天
1 parent bbea6731
......@@ -14,3 +14,4 @@ item_codes = A0018
[sync]
interval_hours = 12
data_range_days = 1800
......@@ -62,11 +62,11 @@ def preprocess_text(text):
if not text: return ""
return str(text).strip()
def fetch_merchants_from_api(api_url, item_codes):
"""从接口获取最近一个月有产值的门店"""
# 计算最近一个月的日期范围
def fetch_merchants_from_api(api_url, item_codes, days_range):
"""从接口获取最近一段时间有产值的门店"""
# 计算日期范围
end_date = datetime.date.today().strftime('%Y-%m-%d')
start_date = (datetime.date.today() - datetime.timedelta(days=30)).strftime('%Y-%m-%d')
start_date = (datetime.date.today() - datetime.timedelta(days=days_range)).strftime('%Y-%m-%d')
payload = {
"dateType": 4,
......@@ -101,11 +101,12 @@ def sync_task():
config = get_config()
api_url = config.get("api", "data_url", fallback="")
item_codes = config.get("api", "item_codes", fallback="")
days_range = config.getint("sync", "data_range_days", fallback=30)
logger.info("开始执行同步任务...")
# 1. 从接口获取数据
api_rows = fetch_merchants_from_api(api_url, item_codes)
api_rows = fetch_merchants_from_api(api_url, item_codes, days_range)
if not api_rows:
logger.warning("未获取到有效数据,跳过本次同步。")
return
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!