bikral 1
bikral
ShadowFon 1
ShadowFon
D 1
delimuratt
PrimeAC 1
PrimeAC
noisiv 1
noisiv
Manwe Work 1
Manwe Work
Best Studio 1
Best Studio
kralhakan2009 1
kralhakan2009
Vahsi Uzman 1
Vahsi Uzman
Hikaye Ekle
Reklam vermek için turkmmo@gmail.com

Altın Konu Python | Mob Drop İtem Anotasyon Scripti

  • Konuyu başlatan Konuyu başlatan Esinti
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 21
  • Görüntüleme Görüntüleme 3K

ROHAN2 WORLD 1-120 TR TİPİ OFFICIAL YOHARA, BALATHOR VE AMON! 80. GÜNÜNDE! +10.000 ONLİNE! HİLE VE BOT %100 ENGELLİ HEMEN TIKLA!

Eline sağlık.
 
Paylaşım için teşekkürler
 
Eline sağlık.
1742317033412.png
 
Paylaşım için teşekkürler, kodunda ufak tefek iyilleştirmeler yaptım. Regex ile precompiled bir pattern ile aramak çok daha performanslı olacaktır, ayrıca error handling kısmında hata alanlar için ekstra detaylar var.
Python:
import re
import os

try:
    from pathlib import Path
except ImportError:
    os.system("pip install pathlib")
    from pathlib import Path

def load_item_names(item_names_filename: str) -> dict[str, str]:
    item_names = {}
    try:
        with open(item_names_filename, "r", encoding="windows-1254", errors="replace") as f:
            for line in f:
                line = line.strip()
                if not line or line.startswith("VNUM"):
                    continue
                parts = line.split("\t", 1) if "\t" in line else line.split(None, 1)
                if len(parts) < 2:
                    continue
                item_names[parts[0]] = parts[1].strip()
    except UnicodeDecodeError as e:
        print(f"Encoding error in {item_names_filename}: {e}")
        print("Using replacement characters for invalid bytes")
    except FileNotFoundError:
        print(f"Error: {item_names_filename} not found")
    except Exception as e:
        print(f"Error reading {item_names_filename}: {e}")
    return item_names

def annotate_mob_drop_items(mob_drop_filename: str, item_names: dict, output_filename: str) -> None:
    pattern = re.compile(r"^\d+\s+(\d+)")
    try:
        with open(mob_drop_filename, "r", encoding="windows-1254", errors="replace") as fin, \
             open(output_filename, "w", encoding="windows-1254") as fout:
            for line in fin:
                if match := pattern.match(line.strip()):
                    vnum = match.group(1)
                    if vnum in item_names:
                        fout.write(f"{line.rstrip()} -- {item_names[vnum]}\n")
                        continue
                fout.write(line)
    except UnicodeDecodeError as e:
        print(f"Encoding error in {mob_drop_filename}: {e}")
        print("Using replacement characters for invalid bytes")
    except FileNotFoundError:
        print(f"Error: {mob_drop_filename} not found")
    except Exception as e:
        print(f"Error processing files: {e}")

def main() -> None:
    current_dir = Path.cwd()
    item_names_file = current_dir / "item_names.txt"
    mob_drop_file = current_dir / "mob_drop_item.txt"
    output_file = current_dir / "new_mob_drop_item.txt"
   
    if not item_names_file.exists() or not mob_drop_file.exists():
        print("Item names or mob drop file not found")
        return
       
    item_names = load_item_names(item_names_file)
    if item_names:
        annotate_mob_drop_items(mob_drop_file, item_names, output_file)
        print(f"Completed: {output_file}")
if __name__ == "__main__":
    main()
 

Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)

Geri
Üst