diff --git a/app/main.py b/app/main.py index 6775851..54f6d3c 100644 --- a/app/main.py +++ b/app/main.py @@ -12,6 +12,7 @@ main.py DRY_RUN=true → 신호만 확인, 주문 전송 안 함 """ +import io import json import os import sys @@ -20,6 +21,12 @@ import logging from datetime import datetime, time from pathlib import Path +# 한글 로그 깨짐 방지 — stdout을 UTF-8로 강제 +if hasattr(sys.stdout, "reconfigure"): + sys.stdout.reconfigure(encoding="utf-8") +elif hasattr(sys.stdout, "buffer"): + sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", line_buffering=True) + # .env 로드 def load_env(): env_path = Path(".env") diff --git a/scripts/run_evening.ps1 b/scripts/run_evening.ps1 index 01eb96f..cc1b5de 100644 --- a/scripts/run_evening.ps1 +++ b/scripts/run_evening.ps1 @@ -1,8 +1,10 @@ # claude_evening 실행 스크립트 # 작업 스케줄러에서 15:30에 실행 (평일) +chcp 65001 | Out-Null # 콘솔 코드페이지 UTF-8 (외부 프로세스 출력 디코딩) $OutputEncoding = [System.Text.Encoding]::UTF8 [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 +$env:PYTHONUTF8 = "1" $env:PYTHONIOENCODING = "utf-8" $PROJECT = Split-Path -Parent $PSScriptRoot diff --git a/scripts/run_midday.ps1 b/scripts/run_midday.ps1 index bff0d3a..3ead57b 100644 --- a/scripts/run_midday.ps1 +++ b/scripts/run_midday.ps1 @@ -1,8 +1,10 @@ # claude_midday 실행 스크립트 # 작업 스케줄러에서 11:20에 실행 (평일) +chcp 65001 | Out-Null # 콘솔 코드페이지 UTF-8 (외부 프로세스 출력 디코딩) $OutputEncoding = [System.Text.Encoding]::UTF8 [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 +$env:PYTHONUTF8 = "1" $env:PYTHONIOENCODING = "utf-8" $PROJECT = Split-Path -Parent $PSScriptRoot diff --git a/scripts/run_morning.ps1 b/scripts/run_morning.ps1 index df428a3..eec24b6 100644 --- a/scripts/run_morning.ps1 +++ b/scripts/run_morning.ps1 @@ -1,8 +1,10 @@ # claude_morning 실행 스크립트 # 작업 스케줄러에서 08:15에 실행 (평일) +chcp 65001 | Out-Null # 콘솔 코드페이지 UTF-8 (외부 프로세스 출력 디코딩) $OutputEncoding = [System.Text.Encoding]::UTF8 [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 +$env:PYTHONUTF8 = "1" $env:PYTHONIOENCODING = "utf-8" $PROJECT = Split-Path -Parent $PSScriptRoot diff --git a/scripts/setup_scheduler.ps1 b/scripts/setup_scheduler.ps1 index c0c4a43..2d71227 100644 --- a/scripts/setup_scheduler.ps1 +++ b/scripts/setup_scheduler.ps1 @@ -1,5 +1,11 @@ # StockBot 작업 스케줄러 등록 (전체 재등록용) # 실행: powershell -ExecutionPolicy Bypass -File scripts\setup_scheduler.ps1 +# 주의: 이 파일은 UTF-8 BOM으로 저장해야 한글 경로가 올바르게 등록됨 + +# 콘솔 인코딩 UTF-8 강제 (한글 경로 깨짐 방지) +[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 +$OutputEncoding = [System.Text.Encoding]::UTF8 +chcp 65001 | Out-Null $PROJECT = "C:\Users\whdwo\OneDrive\바탕 화면\stockbot_v3" $weekdays = @( @@ -15,17 +21,28 @@ function Register-StockTask($name, $time, $script, $limitMin) { -WorkingDirectory $PROJECT $settings = New-ScheduledTaskSettingsSet ` -ExecutionTimeLimit (New-TimeSpan -Minutes $limitMin) ` - -StartWhenAvailable + -StartWhenAvailable ` + -DontStopIfGoingOnBatteries ` + -RunOnlyIfNetworkAvailable:$false Register-ScheduledTask -TaskName $name -TaskPath "\StockBot\" ` - -Trigger $trigger -Action $action -Settings $settings -RunLevel Limited -Force + -Trigger $trigger -Action $action -Settings $settings -RunLevel Limited -Force | Out-Null + + # PowerShell 5.1 버그: Register-ScheduledTask가 한글 경로를 ANSI로 저장 + # → XML export → 경로 수정 → 재import로 교정 + $xml = Export-ScheduledTask -TaskName $name -TaskPath "\StockBot\" + $stored = (Get-ScheduledTask -TaskName $name -TaskPath "\StockBot\").Actions[0].Arguments + if (-not ($stored -match [regex]::Escape("바탕 화면"))) { + $garbled = ($stored -replace '.*OneDrive\\(.+?)\\stockbot.*', '$1') + if ($garbled -ne $stored) { + $fixedXml = $xml.Replace($garbled, "바탕 화면") + Register-ScheduledTask -TaskName $name -TaskPath "\StockBot\" -Xml $fixedXml -Force | Out-Null + } + } Write-Host "[OK] $name 등록 완료 (평일 $time)" -ForegroundColor Green } -# ── 4개 태스크 등록 ────────────────────────────────────────────────────────── -# 07:55 claude /start-bot → Python 봇 백그라운드 시작 -Register-StockTask "StockBot_Bot" "07:55" "run_bot.ps1" 10 - -# 08:15 claude /morning → 뉴스+KIS 수집 → daily_context.json +# ── 3개 태스크 등록 (StockBot_Bot 제거 — /morning이 /start-bot을 호출함) ──── +# 08:15 claude /morning → 뉴스+KIS 수집 → daily_context.json → /start-bot 호출 Register-StockTask "StockBot_Morning" "08:15" "run_morning.ps1" 20 # 11:20 claude /midday → 장중 스냅샷 → midday_context.json → 점심 세션 시작 @@ -34,6 +51,13 @@ Register-StockTask "StockBot_Midday" "11:20" "run_midday.ps1" 20 # 15:30 claude /evening → 결과 분석 → 리포트 → Discord Register-StockTask "StockBot_Evening" "15:30" "run_evening.ps1" 30 +# StockBot_Bot 비활성화 유지 (이미 존재할 경우) +$botTask = Get-ScheduledTask -TaskName "StockBot_Bot" -TaskPath "\StockBot\" -ErrorAction SilentlyContinue +if ($botTask) { + Disable-ScheduledTask -TaskName "StockBot_Bot" -TaskPath "\StockBot\" | Out-Null + Write-Host "[OK] StockBot_Bot 비활성화 유지" -ForegroundColor Yellow +} + Write-Host "" Write-Host "등록된 작업:" -ForegroundColor Cyan Get-ScheduledTask -TaskPath "\StockBot\" | Format-Table TaskName, State