# Daily report: generate + push to WeCom webhook # Usage: # .\run-daily.ps1 # .\run-daily.ps1 -SkipPush # .\run-daily.ps1 -SkipGenerate param( [switch]$SkipPush, [switch]$SkipGenerate ) $ErrorActionPreference = "Stop" $Root = Split-Path -Parent $MyInvocation.MyCommand.Path Set-Location $Root function Import-DotEnvFile { param([string]$Path) if (-not (Test-Path $Path)) { return } Get-Content $Path -Encoding UTF8 | ForEach-Object { if ($_ -match '^\s*#' -or $_ -notmatch '=') { return } $pair = $_ -split '=', 2 if ($pair.Count -eq 2) { $name = $pair[0].Trim() $value = $pair[1].Trim().Trim('"').Trim("'") if ($name -and $value) { Set-Item -Path "Env:$name" -Value $value } } } } Import-DotEnvFile (Join-Path $Root ".env") Import-DotEnvFile (Join-Path $Root ".env.local") $python = "python" $date = Get-Date -Format "yyyy-MM-dd" $reportWecom = Join-Path $Root "output\$date.wecom.md" if (-not $SkipGenerate) { Write-Host "Generating daily report: $date" & $python -m daily generate if ($LASTEXITCODE -ne 0) { throw "daily generate failed with exit code $LASTEXITCODE" } } if (-not $SkipPush) { if (-not (Test-Path $reportWecom)) { throw "Report not found: $reportWecom" } Write-Host "Pushing to WeCom webhook..." & $python -m daily push $reportWecom if ($LASTEXITCODE -ne 0) { throw "daily push failed with exit code $LASTEXITCODE" } } Write-Host "Done: $date"