contacts battle works...
This commit is contained in:
30
UnRLE/0864_DemnCONTC/duplicates.py
Normal file
30
UnRLE/0864_DemnCONTC/duplicates.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
# Создаем словарь для группировки
|
||||
file_groups = {}
|
||||
|
||||
# Ищем все .txt файлы
|
||||
for filename in [f for f in os.listdir('.') if f.endswith('.txt') and os.path.isfile(f)]:
|
||||
try:
|
||||
with open(filename, 'rb') as f:
|
||||
content = f.read()
|
||||
file_hash = hashlib.md5(content).hexdigest()
|
||||
|
||||
# Добавляем в группу
|
||||
file_groups.setdefault(file_hash, []).append(filename)
|
||||
except:
|
||||
pass
|
||||
|
||||
# Преобразуем в нужный формат
|
||||
result = list(file_groups.values())
|
||||
|
||||
# Сохраняем в JSON
|
||||
with open("contacts_copy.json", 'w') as f:
|
||||
json.dump(result, f, indent=2)
|
||||
|
||||
# Выводим статистику
|
||||
print(f"Найдено файлов: {sum(len(g) for g in result)}")
|
||||
print(f"Создано групп: {len(result)}")
|
||||
print(f"Сохранено в contacts_copy.json")
|
||||
Reference in New Issue
Block a user