import os def generate_codebase(root_dir, output_file): # Папки, которые мы игнорируем ignore_dirs = {'.git', 'vendor', '__pycache__', 'node_modules', '.idea', '.vscode'} # Расширения файлов, которые нам не нужны (бинарники и контрольные суммы) ignore_exts = {'.pyc', '.sum', '.exe', '.dll', '.so', '.pdf', '.png', '.jpg'} with open(output_file, 'w', encoding='utf-8') as outfile: for root, dirs, files in os.walk(root_dir): # Исключаем игнорируемые директории, модифицируя список dirs на месте dirs[:] = [d for d in dirs if d not in ignore_dirs] for file in files: # Пропускаем сам выходной файл, этот скрипт и файлы с ненужными расширениями if file == output_file or file == "code2text.py" or any(file.endswith(ext) for ext in ignore_exts): continue filepath = os.path.join(root, file) try: with open(filepath, 'r', encoding='utf-8') as infile: outfile.write(f"\n\n=== ФАЙЛ: {filepath} ===\n") outfile.write(infile.read()) except Exception as e: # Если файл нельзя прочитать как текст (например, это картинка без расширения), просто запишем ошибку и пойдем дальше outfile.write(f"\n\n=== ПРОПУЩЕН БИНАРНЫЙ ФАЙЛ ИЛИ ОШИБКА ЧТЕНИЯ: {filepath} ===\n") if __name__ == "__main__": # Меняем '.' на './service/telegram_service' (или как у вас называется эта папка) generate_codebase('./service/telegram_service', 'telegram_codebase.txt') print("Готово! Код собран в файл telegram_codebase.txt")