Files
Ferocit-comfyui-feroccustom…/random_line_from_text_node.py
Claude 529f97e87e Add module-level docstrings to all modules (closes #18)
Added one-line module docstrings to config.py, file_utils.py,
load_description_node.py, and random_line_from_text_node.py to
improve navigability and IDE support.

https://claude.ai/code/session_01JBWyFr5shvPXUPmZkX3Nhg
2026-03-23 18:18:49 +00:00

47 lines
1.4 KiB
Python

"""ComfyUI custom node for selecting a random line from one or more text files."""
import random
try:
from .config import MAX_SEED, MAX_FILE_INPUTS
from .file_utils import read_random_line
except ImportError:
from config import MAX_SEED, MAX_FILE_INPUTS
from file_utils import read_random_line
class RandomLineFromTextNode:
@classmethod
def INPUT_TYPES(cls):
optional = {
f"file_path_{i}": ("STRING", {"default": ""})
for i in range(1, MAX_FILE_INPUTS + 1)
}
return {
"required": {
"seed": ("INT", {"default": 0, "min": 0, "max": MAX_SEED}),
},
"optional": optional,
}
CATEGORY = "Feroc"
RETURN_TYPES = ("STRING",)
FUNCTION = "get_random_lines"
def get_random_lines(self, seed: int, **kwargs) -> tuple[str]:
"""Select one random line from each provided text file.
Returns:
Tuple containing a single string with all selected lines joined by newline.
"""
rng = random.Random(seed)
file_paths = [kwargs.get(f'file_path_{i}') for i in range(1, MAX_FILE_INPUTS + 1)]
selected_lines = []
for path in file_paths:
if path and path.strip():
line = read_random_line(path, rng)
if line is not None:
selected_lines.append(line)
return ("\n".join(selected_lines),)