plagiat.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """
  2. https://www.cyberforum.ru/python-graphics/thread2712141.html
  3. """
  4. import os
  5. from difflib import SequenceMatcher
  6. # директория файла
  7. BASE_DIR = os.path.abspath(os.path.dirname(__file__))
  8. files_path = []
  9. dirs = os.listdir(BASE_DIR)
  10. for dir in dirs:
  11. dir_path = os.path.join(BASE_DIR, dir)
  12. if os.path.isdir(dir_path) and (dir != "__pycache__"):
  13. files = os.listdir(dir_path)
  14. for file in files:
  15. file_path = os.path.join(BASE_DIR, dir, file)
  16. filename, fileext = os.path.splitext(file)
  17. if os.path.isfile(file_path) and (fileext=='.md'):
  18. files_path.append(file_path)
  19. for file_1 in files_path:
  20. for file_2 in files_path:
  21. if (file_1 != file_2):
  22. with open(file_1, encoding="utf-8") as f_1:
  23. str1 = f_1.read()
  24. with open(file_2, encoding="utf-8") as f_2:
  25. str2 = f_2.read()
  26. ratio = int(SequenceMatcher(None, str1.lower(), str2.lower()).ratio() * 100)
  27. if (ratio > 70):
  28. print(file_2)
  29. print(file_1)
  30. print(f"ratio = {ratio}")
  31. print()
  32. print("success")