1
0
Selaa lähdekoodia

plagiat - перекодировка

ypv 2 vuotta sitten
vanhempi
commit
dcff91fbcc

+ 31 - 9
Учебная практика 46 гр. 1 сем. - 2/Вопросы/plagiat.py

@@ -8,7 +8,8 @@ from tqdm import tqdm
 # директория файла
 BASE_DIR = os.path.abspath(os.path.dirname(__file__))
 
-files_path = []
+print()
+files_paths = []
 dirs = os.listdir(BASE_DIR)
 for dir in dirs:
     dir_path = os.path.join(BASE_DIR, dir)
@@ -19,16 +20,37 @@ for dir in dirs:
             filename, fileext = os.path.splitext(file)
 
             if os.path.isfile(file_path) and (fileext=='.md'):
-                files_path.append(file_path)
+                files_paths.append(file_path)
 
-
-for file_1 in tqdm(files_path):
-    for file_2 in files_path:
+print(f"Всего файлов: {len(files_paths)}")
+for file_1 in tqdm(files_paths):
+    for file_2 in files_paths:
         if (file_1 != file_2):
-            with open(file_1, encoding="utf-8") as f_1:
-                str1 = f_1.read()
-            with open(file_2, encoding="utf-8") as f_2:
-                str2 = f_2.read()
+            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):