159 lines
4.8 KiB
Python
159 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
EXECUTE SIMPLE RENAME - Dejansko preimenuje vse datoteke
|
|
"""
|
|
|
|
import re
|
|
import json
|
|
from pathlib import Path
|
|
from collections import Counter
|
|
|
|
REFERENCA_DIR = Path("/Users/davidkotnik/repos/novafarma/assets/slike/glavna_referenca")
|
|
|
|
# Pattern matching (enak kot prej)
|
|
PATTERNS = {
|
|
'scientist': ['scientist'],
|
|
'herbalist': ['herbalist'],
|
|
'shepherd': ['shepherd'],
|
|
'tracker': ['tracker'],
|
|
'dancer': ['dancer'],
|
|
'botanist': ['botanist'],
|
|
'merchant': ['merchant'],
|
|
'priest': ['priest'],
|
|
'farmer': ['farmer'],
|
|
'guard': ['guard'],
|
|
'kai': ['kai'],
|
|
'ana': ['ana'],
|
|
'gronk': ['gronk'],
|
|
'wheat': ['wheat'],
|
|
'corn': ['corn', 'koruza'],
|
|
'potato': ['potato', 'krompir'],
|
|
'carrot': ['carrot', 'korenje'],
|
|
'tomato': ['tomato', 'paradiznik'],
|
|
'cannabis': ['cannabis', 'konoplja', 'ganja'],
|
|
'onion': ['onion', 'cebula'],
|
|
'pepper': ['pepper', 'paprika'],
|
|
'mushroom': ['mushroom'],
|
|
'apple': ['apple', 'jablana'],
|
|
'cherry': ['cherry', 'visnja'],
|
|
'orange': ['orange', 'pomaranča'],
|
|
'pear': ['pear', 'hruška'],
|
|
'oak': ['oak'],
|
|
'pine': ['pine'],
|
|
'house': ['house', 'hisa'],
|
|
'barn': ['barn', 'hlev'],
|
|
'church': ['church', 'cerkev'],
|
|
'school': ['school', 'sola'],
|
|
'hospital': ['hospital'],
|
|
'fence': ['fence'],
|
|
'chest': ['chest'],
|
|
'barrel': ['barrel'],
|
|
'tent': ['tent'],
|
|
'axe': ['axe', 'sekira'],
|
|
'zombie': ['zombie', 'zombi'],
|
|
'ghost': ['ghost', 'duh'],
|
|
}
|
|
|
|
def smart_categorize(filename):
|
|
"""Prepozna kategorijo iz imena"""
|
|
filename_lower = filename.lower()
|
|
|
|
for simple_name, keywords in PATTERNS.items():
|
|
for keyword in keywords:
|
|
if keyword in filename_lower:
|
|
return simple_name
|
|
|
|
# Default
|
|
clean = filename
|
|
clean = re.sub(r'^(moje_slike_koncna|src_assets|assets)_', '', clean, flags=re.IGNORECASE)
|
|
clean = re.sub(r'_(library|godot|references)_?', '', clean, flags=re.IGNORECASE)
|
|
clean = re.sub(r'\d+_', '', clean)
|
|
|
|
words = re.split(r'[_\-\s]+', clean)
|
|
for word in words:
|
|
if len(word) > 3:
|
|
return word.lower()
|
|
|
|
return 'unknown'
|
|
|
|
def execute_rename():
|
|
"""Izvrši rename"""
|
|
print("🔄 ZAČENJAM PREIMENOVANJE...\n")
|
|
|
|
all_files = list(REFERENCA_DIR.glob('*.png')) + list(REFERENCA_DIR.glob('*.jpg'))
|
|
|
|
# Kategoriziraj
|
|
categorized = {}
|
|
for filepath in all_files:
|
|
category = smart_categorize(filepath.stem)
|
|
if category not in categorized:
|
|
categorized[category] = []
|
|
categorized[category].append(filepath)
|
|
|
|
# Rename
|
|
renamed = []
|
|
errors = []
|
|
|
|
for category, files in sorted(categorized.items()):
|
|
if len(files) == 1:
|
|
old_path = files[0]
|
|
new_name = f"{category}{old_path.suffix}"
|
|
new_path = REFERENCA_DIR / new_name
|
|
|
|
try:
|
|
if not new_path.exists():
|
|
old_path.rename(new_path)
|
|
renamed.append((old_path.name, new_name))
|
|
else:
|
|
errors.append(f"Already exists: {new_name}")
|
|
except Exception as e:
|
|
errors.append(f"Error: {old_path.name} → {e}")
|
|
else:
|
|
for i, old_path in enumerate(files, 1):
|
|
new_name = f"{category}{i}{old_path.suffix}"
|
|
new_path = REFERENCA_DIR / new_name
|
|
|
|
try:
|
|
if not new_path.exists():
|
|
old_path.rename(new_path)
|
|
renamed.append((old_path.name, new_name))
|
|
else:
|
|
errors.append(f"Already exists: {new_name}")
|
|
except Exception as e:
|
|
errors.append(f"Error: {old_path.name} → {e}")
|
|
|
|
if i % 100 == 0:
|
|
print(f" Obdelanih: {len(renamed)}/{len(all_files)}")
|
|
|
|
# Poročilo
|
|
print("\n" + "=" * 80)
|
|
print(" KONČNO POROČILO")
|
|
print("=" * 80)
|
|
print(f"✅ Uspešno preimenovanih: {len(renamed)}")
|
|
print(f"❌ Napak: {len(errors)}")
|
|
print("=" * 80)
|
|
|
|
if errors:
|
|
print("\n⚠️ NAPAKE:")
|
|
for err in errors[:20]:
|
|
print(f" {err}")
|
|
if len(errors) > 20:
|
|
print(f" ... in še {len(errors) - 20} napak")
|
|
|
|
# Shrani log
|
|
log_file = REFERENCA_DIR / "rename_log.txt"
|
|
with open(log_file, 'w', encoding='utf-8') as f:
|
|
f.write("SIMPLE RENAME LOG\n")
|
|
f.write("=" * 80 + "\n\n")
|
|
for old, new in renamed:
|
|
f.write(f"{old} → {new}\n")
|
|
|
|
print(f"\n📄 Log shranjen: rename_log.txt")
|
|
print(f"\n🎉 PREIMENOVANJE KONČANO!")
|
|
|
|
if __name__ == "__main__":
|
|
print("=" * 80)
|
|
print(" EXECUTE SIMPLE RENAME")
|
|
print("=" * 80)
|
|
execute_rename()
|