Cai
2026-08-14 783dbe9738755902e1b86d99f14ddf698f1a0033
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
param(
    [string]$Python = "python",
    [string]$AsOf = "latest",
    [string]$Database = "stock_valuation",
    [string]$Config = ""
)
 
$ErrorActionPreference = "Stop"
$ProjectRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..\..\..")).Path
$ModuleRoot = Join-Path $ProjectRoot "dev\project-dev"
$ValuationRootName = -join @([char]0x80A1, [char]0x7968, [char]0x4F30, [char]0x503C)
$LedgerName = -join @([char]0x4F30, [char]0x503C, [char]0x53F0, [char]0x8D26)
$ResultRoot = Join-Path $ProjectRoot "ana-data\result"
$LedgerDir = Join-Path (Join-Path $ResultRoot $ValuationRootName) $LedgerName
$LogDir = Join-Path $LedgerDir "logs"
New-Item -ItemType Directory -Force -Path $LogDir | Out-Null
$RunStamp = Get-Date -Format "yyyyMMdd-HHmmss"
$LogPath = Join-Path $LogDir "daily-$RunStamp.log"
 
$PreviousPythonPath = $env:PYTHONPATH
try {
    $env:PYTHONPATH = if ($PreviousPythonPath) { "$ModuleRoot;$PreviousPythonPath" } else { $ModuleRoot }
    $Arguments = @("-m", "stock_valuation_ledger", "daily", "--as-of", $AsOf, "--database", $Database)
    if ($Config) {
        $Arguments += @("--config", (Resolve-Path -LiteralPath $Config).Path)
    }
    Push-Location $ProjectRoot
    try {
        & $Python @Arguments 2>&1 | Tee-Object -FilePath $LogPath
        $ExitCode = $LASTEXITCODE
    }
    finally {
        Pop-Location
    }
}
finally {
    $env:PYTHONPATH = $PreviousPythonPath
}
 
exit $ExitCode