Spaces:
Sleeping
Sleeping
| """Duplicate image URL logging.""" | |
| import logging | |
| from datetime import datetime | |
| from image_resizer.config import DUPLICATE_LOG_PATH | |
| from image_resizer.models import DuplicateRecord | |
| logger = logging.getLogger(__name__) | |
| def log_duplicates(records: list[DuplicateRecord]) -> None: | |
| """Append duplicate URL entries to the log file.""" | |
| if not records: | |
| return | |
| timestamp = datetime.now().isoformat(timespec="seconds") | |
| lines: list[str] = [] | |
| for record in records: | |
| lines.append( | |
| f"{timestamp}\t{record['row']}\t{record['original_row']}\t" | |
| f"{record['sheet']}\t{record['column']}\t{record['url']}\t" | |
| f"{record['name']}\t{record['original_name']}\n" | |
| ) | |
| try: | |
| with open(DUPLICATE_LOG_PATH, "a", encoding="utf-8") as f: | |
| f.writelines(lines) | |
| except OSError as e: | |
| logger.error("Could not write to %s: %s", DUPLICATE_LOG_PATH, e) | |