package tools import ( "context" "log" "time" "weatherstation/internal/config" "weatherstation/internal/forecast" ) // RunForecastFetchForDay 按指定“日期”(CST)抓取当天0点到当前时间后三小时的预报(Open-Meteo 与 彩云) // dateStr: 形如 "2006-01-02"(按 Asia/Shanghai 解析) func RunForecastFetchForDay(ctx context.Context, dateStr string) error { loc, _ := time.LoadLocation("Asia/Shanghai") if loc == nil { loc = time.FixedZone("CST", 8*3600) } dayStart, err := time.ParseInLocation("2006-01-02", dateStr, loc) if err != nil { return err } now := time.Now().In(loc) // 窗口:dayStart .. now+3h 的各整点(写库函数内部按 issued_at=当前时间) // 目前 open-meteo 与彩云抓取函数都是"取未来三小时"的固定窗口。 // 这里采用:先执行一次 open-meteo 与彩云的"未来三小时"写入,作为当下 issued 版本。 log.Printf("开始抓取 Open-Meteo 预报...") if err := forecast.RunOpenMeteoFetch(ctx); err != nil { log.Printf("Open-Meteo 抓取失败: %v", err) } else { log.Printf("Open-Meteo 抓取完成") } token := config.GetConfig().Forecast.CaiyunToken log.Printf("彩云 token: %s", token) if token != "" { log.Printf("开始抓取彩云预报...") if err := forecast.RunCaiyunFetch(ctx, token); err != nil { log.Printf("彩云 抓取失败: %v", err) } else { log.Printf("彩云抓取完成") } } else { log.Printf("未配置彩云 token,跳过彩云抓取") } _ = dayStart _ = now return nil }