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
|