Skip to content

Commit

Permalink
Sort templates
Browse files Browse the repository at this point in the history
  • Loading branch information
parsiad committed Jun 3, 2024
1 parent b06144d commit 00c66f3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion nexus_autodl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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")

Expand Down

0 comments on commit 00c66f3

Please sign in to comment.