fix(main): load .env file and respect USE_MOCK_DATA setting

- Add python-dotenv to load .env configuration
- Read USE_MOCK_DATA and EU_CHAT_LOG_PATH from environment
- Use real game log when USE_MOCK_DATA=false
- Show correct mode (Mock vs Live) in header
- Import os module for environment access

Fixes issue where app always used mock data regardless of .env settings.
This commit is contained in:
LemonNexus 2026-02-08 18:01:39 +00:00
parent bd506e53c2
commit 6ce23718bc
1 changed files with 21 additions and 5 deletions

26
main.py
View File

@ -5,11 +5,17 @@
import sys
import asyncio
import signal
import os
from pathlib import Path
from decimal import Decimal
from datetime import datetime
import logging
# Load .env file before anything else
from dotenv import load_dotenv
env_path = Path(__file__).parent / ".env"
load_dotenv(dotenv_path=env_path)
# Add core to path
core_dir = Path(__file__).parent / "core"
sys.path.insert(0, str(core_dir))
@ -75,7 +81,10 @@ class LemontropiaApp:
"""Print application header."""
print("\n" + "="*65)
print(" 🍋 LEMONTROPIA SUITE — User Test Build v0.1.0")
print(" Core Data Capture Engine — Mock Mode")
if os.getenv('USE_MOCK_DATA', 'true').lower() in ('true', '1', 'yes'):
print(" Core Data Capture Engine — Mock Mode")
else:
print(" Core Data Capture Engine — Live Mode")
print("="*65)
print("\n 📚 TERMINOLOGY:")
print(" • PROJECT = Activity type (Hunt/Mine/Craft)")
@ -184,11 +193,18 @@ class LemontropiaApp:
session = self.pm.start_session(project.id, notes=session_notes)
print(f"✅ SESSION started: ID {session.id}")
# Setup log watcher
test_data_dir = Path(__file__).parent / "test-data"
mock_log = test_data_dir / "mock-chat.log"
# Setup log watcher - use real log or mock based on .env
use_mock = os.getenv('USE_MOCK_DATA', 'true').lower() in ('true', '1', 'yes')
log_path = os.getenv('EU_CHAT_LOG_PATH', '')
self.watcher = LogWatcher(str(mock_log), poll_interval=2.0, mock_mode=True)
if use_mock or not log_path:
test_data_dir = Path(__file__).parent / "test-data"
mock_log = test_data_dir / "mock-chat.log"
self.watcher = LogWatcher(str(mock_log), poll_interval=2.0, mock_mode=True)
logger.info("Using MOCK data for testing")
else:
self.watcher = LogWatcher(log_path, poll_interval=1.0, mock_mode=False)
logger.info(f"Using REAL log: {log_path}")
# Stats tracking
stats = {'loot': 0, 'globals': 0, 'hofs': 0, 'skills': 0, 'total_ped': Decimal('0.0')}