diff --git a/nexus_autodl.py b/nexus_autodl.py index 4417df5..bd9acf5 100755 --- a/nexus_autodl.py +++ b/nexus_autodl.py @@ -2,9 +2,11 @@ import logging import random +import re import sys import time from pathlib import Path +from typing import Iterator import click import pyautogui @@ -16,6 +18,15 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s") +def human_sorted(paths: Iterator[Path]) -> list[Path]: + pattern = re.compile("([0-9]+)") + + def key(key: Path) -> tuple[int | str, ...]: + return tuple(int(c) if c.isdigit() else c for c in pattern.split(str(key))) + + return sorted(paths, key=key) + + @click.command() @click.option("--confidence", default=0.7, show_default=True) @click.option("--grayscale/--color", default=True, show_default=True) @@ -31,9 +42,10 @@ def main( ) -> None: templates_path_ = Path(templates_path) templates: dict[Path, Image] = {} - for template_path in templates_path_.rglob("*"): + for template_path in human_sorted(templates_path_.iterdir()): try: templates[template_path] = open_image(template_path) + logging.info(f"Loaded {template_path}") except UnidentifiedImageError: logging.info(f"{template_path} is not a valid image; skipping")