From ea297da0c8c00cf7d722466658e5656b22697d70 Mon Sep 17 00:00:00 2001 From: rambros Date: Sat, 21 Mar 2026 01:23:21 +0530 Subject: [PATCH] fix random users json in compiled binaries --- disco-reaper.spec | 2 +- src/core/database.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/disco-reaper.spec b/disco-reaper.spec index bc5253a..e73ff51 100644 --- a/disco-reaper.spec +++ b/disco-reaper.spec @@ -20,7 +20,7 @@ a = Analysis( ['disco-reaper.py'], pathex=[], binaries=[], - datas=[('src/first-info.md', 'src')], + datas=[('src/first-info.md', 'src'), ('src/random_users.json', 'src')], hiddenimports=hiddenimports, hookspath=[], hooksconfig={}, diff --git a/src/core/database.py b/src/core/database.py index b1ffd4f..b2230b9 100644 --- a/src/core/database.py +++ b/src/core/database.py @@ -5,6 +5,7 @@ import random from pathlib import Path from typing import Optional, Dict, Any import threading +import sys logger = logging.getLogger(__name__) @@ -167,7 +168,18 @@ class MigrationDatabase: def _generate_alias(self) -> str: """Generates a unique alias in the format {Adjective}{Name} from random_users.json.""" - json_path = Path(__file__).parent.parent / "random_users.json" + # Robust path resolution for PyInstaller + if hasattr(sys, '_MEIPASS'): + # Running as a frozen bundle + json_path = Path(sys._MEIPASS) / "src" / "random_users.json" + else: + # Running in normal python environment (from src/core/) + json_path = Path(__file__).parent.parent / "random_users.json" + + if not json_path.exists(): + logger.error(f"MigrationDatabase: random_users.json not found at {json_path}") + raise FileNotFoundError(f"Missing required resource: {json_path}") + with open(json_path, "r", encoding="utf-8") as f: data = json.load(f)