|
@@ -4,12 +4,14 @@ https://www.cyberforum.ru/python-graphics/thread2712141.html
|
|
|
import os
|
|
|
from difflib import SequenceMatcher
|
|
|
from tqdm import tqdm
|
|
|
+import datetime
|
|
|
|
|
|
# директория файла
|
|
|
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
print()
|
|
|
files_paths = []
|
|
|
+exec_files_paths = [] # уже проверенные
|
|
|
dirs = os.listdir(BASE_DIR)
|
|
|
for dir in dirs:
|
|
|
dir_path = os.path.join(BASE_DIR, dir)
|
|
@@ -22,42 +24,64 @@ for dir in dirs:
|
|
|
if os.path.isfile(file_path) and (fileext=='.md'):
|
|
|
files_paths.append(file_path)
|
|
|
|
|
|
-print(f"Всего файлов: {len(files_paths)}")
|
|
|
+now = datetime.datetime.now().strftime('%d-%m-%Y %H:%M')
|
|
|
+out_str = f"Время проверки: {now} \n"
|
|
|
+print(out_str)
|
|
|
+
|
|
|
+
|
|
|
for file_1 in tqdm(files_paths):
|
|
|
for file_2 in files_paths:
|
|
|
if (file_1 != file_2):
|
|
|
- try:
|
|
|
- with open(file_1, encoding="utf-8") as f_1:
|
|
|
- str1 = f_1.read()
|
|
|
- except:
|
|
|
- with open(file_1, encoding="cp1251") as f_1:
|
|
|
- str1 = f_1.read()
|
|
|
- f_1.close()
|
|
|
- with open(file_1, 'w', encoding="utf-8") as f_1:
|
|
|
- f_1.write(str1)
|
|
|
- f_1.close()
|
|
|
-
|
|
|
- try:
|
|
|
- with open(file_2, encoding="utf-8") as f_2:
|
|
|
- str2 = f_2.read()
|
|
|
- except:
|
|
|
- print()
|
|
|
- print(file_2)
|
|
|
- print("Неверная кодировка")
|
|
|
- with open(file_2, encoding="cp1251") as f_2:
|
|
|
- str2 = f_2.read()
|
|
|
- f_2.close()
|
|
|
- with open(file_2, 'w', encoding="utf-8") as f_2:
|
|
|
- f_2.write(str2)
|
|
|
- f_2.close()
|
|
|
-
|
|
|
-
|
|
|
- ratio = int(SequenceMatcher(None, str1.lower(), str2.lower()).ratio() * 100)
|
|
|
- if (ratio > 70):
|
|
|
- print(file_2)
|
|
|
- print(file_1)
|
|
|
- print(f"ratio = {ratio}")
|
|
|
- print()
|
|
|
+ small_filename_1 = str(file_1).replace(BASE_DIR, "").strip("\\")
|
|
|
+ small_filename_2 = str(file_2).replace(BASE_DIR, "").strip("\\")
|
|
|
+ if not (f"{small_filename_2}|{small_filename_1}") in exec_files_paths: # проверка на уже пройденное сравнение
|
|
|
+
|
|
|
+ try:
|
|
|
+ with open(file_1, encoding="utf-8") as f_1:
|
|
|
+ str1 = f_1.read()
|
|
|
+ except:
|
|
|
+ with open(file_1, encoding="cp1251") as f_1:
|
|
|
+ str1 = f_1.read()
|
|
|
+ f_1.close()
|
|
|
+ with open(file_1, 'w', encoding="utf-8") as f_1:
|
|
|
+ f_1.write(str1)
|
|
|
+ f_1.close()
|
|
|
+
|
|
|
+ try:
|
|
|
+ with open(file_2, encoding="utf-8") as f_2:
|
|
|
+ str2 = f_2.read()
|
|
|
+ except:
|
|
|
+ with open(file_2, encoding="cp1251") as f_2:
|
|
|
+ str2 = f_2.read()
|
|
|
+ f_2.close()
|
|
|
+ with open(file_2, 'w', encoding="utf-8") as f_2:
|
|
|
+ f_2.write(str2)
|
|
|
+ f_2.close()
|
|
|
+
|
|
|
+
|
|
|
+ ratio = int(SequenceMatcher(None, str1.lower(), str2.lower()).ratio() * 100)
|
|
|
+ if (ratio > 70):
|
|
|
+ # время создания файла
|
|
|
+ later_file = small_filename_1
|
|
|
+ if (os.path.getctime(file_1) < os.path.getctime(file_2)):
|
|
|
+ later_file = small_filename_2
|
|
|
+ out_str += f"{small_filename_2}\n"
|
|
|
+ out_str += f"ratio = {ratio}\n"
|
|
|
+
|
|
|
+ exec_files_paths.append(f"{small_filename_1}|{small_filename_2}")
|
|
|
+
|
|
|
+out_str +="\n\n"
|
|
|
+print(out_str)
|
|
|
+
|
|
|
+# запись лога
|
|
|
+log_path = os.path.join(BASE_DIR, "log.md")
|
|
|
+with open(log_path, "r", encoding="utf-8") as f_log:
|
|
|
+ prev_str = f_log.read()
|
|
|
+
|
|
|
+prev_str = out_str + prev_str
|
|
|
+with open(log_path, "w", encoding="utf-8") as f_log:
|
|
|
+ f_log.write(prev_str)
|
|
|
+ f_log.close()
|
|
|
|
|
|
|
|
|
print("success")
|