1
0

plagiat_1.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """
  2. https://www.cyberforum.ru/python-graphics/thread2712141.html
  3. """
  4. import os
  5. from difflib import SequenceMatcher
  6. from tqdm import tqdm
  7. import datetime
  8. import requests
  9. # ссылка для проверки
  10. url = "http://213.155.192.79:3001/ypv/up/raw/master/%d0%a3%d1%87%d0%b5%d0%b1%d0%bd%d0%b0%d1%8f%20%d0%bf%d1%80%d0%b0%d0%ba%d1%82%d0%b8%d0%ba%d0%b0%2046%20%d0%b3%d1%80.%201%20%d1%81%d0%b5%d0%bc.%20-%202/%d0%92%d0%be%d0%bf%d1%80%d0%be%d1%81%d1%8b/%d0%a1%d0%ba%d0%b2%d0%be%d1%80%d1%86%d0%be%d0%b2%d0%b0%20%d0%94%d0%b8%d0%b0%d0%bd%d0%b03/%d0%92%d0%be%d0%bf%d1%80%d0%be%d1%81%2016.md"
  11. # директория файла
  12. BASE_DIR = os.path.abspath(os.path.dirname(__file__))
  13. print()
  14. response = requests.get(url)
  15. post_html = response.text
  16. files_paths = []
  17. dirs = os.listdir(BASE_DIR)
  18. for dir in dirs:
  19. dir_path = os.path.join(BASE_DIR, dir)
  20. if os.path.isdir(dir_path) and (dir != "__pycache__"):
  21. files = os.listdir(dir_path)
  22. for file in files:
  23. file_path = os.path.join(BASE_DIR, dir, file)
  24. filename, fileext = os.path.splitext(file)
  25. if os.path.isfile(file_path) and (fileext=='.md'):
  26. files_paths.append(file_path)
  27. out_str = ""
  28. max_ratio = 0
  29. max_ratio_file = ""
  30. for file_1 in tqdm(files_paths):
  31. small_filename_1 = str(file_1).replace(BASE_DIR, "").strip("\\")
  32. try:
  33. with open(file_1, encoding="utf-8") as f_1:
  34. str1 = f_1.read()
  35. except:
  36. with open(file_1, encoding="cp1251") as f_1:
  37. str1 = f_1.read()
  38. f_1.close()
  39. with open(file_1, 'w', encoding="utf-8") as f_1:
  40. f_1.write(str1)
  41. f_1.close()
  42. ratio = int(SequenceMatcher(None, str1.lower(), post_html.lower()).ratio() * 100)
  43. if (ratio > 70):
  44. out_str += f"{small_filename_1}\n"
  45. out_str += f"ratio = {ratio}\n"
  46. if (ratio > max_ratio):
  47. max_ratio = ratio
  48. max_ratio_file = small_filename_1
  49. print(out_str)
  50. print()
  51. print(f"max ratio: {max_ratio}%")
  52. print(f"max ratio file: {max_ratio_file}")
  53. print("success")