Spaces:
Running
Running
import os | |
import json | |
def merge_json_files(folder_path, output_file): | |
merged_data = [] | |
if not os.path.exists(folder_path): | |
print(f"Папка '{folder_path}' не существует.") | |
return | |
for filename in os.listdir(folder_path): | |
if filename.endswith('.json'): | |
file_path = os.path.join(folder_path, filename) | |
try: | |
with open(file_path, 'r', encoding='utf-8') as f: | |
data = json.load(f) | |
merged_data.append(data) | |
except Exception as e: | |
print(f"Ошибка при чтении файла '{file_path}': {e}") | |
with open(output_file, 'w', encoding='utf-8') as f: | |
json.dump(merged_data, f, ensure_ascii=False, indent=4) | |
print(f"Данные успешно объединены и сохранены в файл '{output_file}'.") | |
if __name__ == "__main__": | |
folder_path = './model_data/external' | |
output_file = 'leaderboard.json' | |
merge_json_files(folder_path, output_file) | |