Advertisement
Amorf

Untitled

Oct 7th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. import os.path
  2. import re
  3. import eel
  4.  
  5. countOfOperators = 0
  6. countOfOperands = 0
  7.  
  8. operatorsDictionary = 0
  9. operandsDictionary = 0
  10.  
  11. @eel.expose
  12. def get_operators():
  13.     operators = open("operatorsOutput.txt", "r").read()
  14.     return operators
  15.  
  16. @eel.expose
  17. def get_operands():
  18.     operators = open("operandsOutput.txt", "r").read()
  19.     return operators
  20.  
  21. @eel.expose
  22. def get_count_of_operators():
  23.     return countOfOperators
  24.  
  25. @eel.expose
  26. def get_count_of_operands():
  27.     return countOfOperands
  28.  
  29. @eel.expose
  30. def get_dictionary_of_operators():
  31.     return operatorsDictionary
  32.  
  33. @eel.expose
  34. def get_dictionary_of_operands():
  35.     return operandsDictionary
  36.  
  37. if (os.path.isfile("code.txt") and os.path.isfile("operators.txt")):
  38.     text = open("code.txt", "r").read()
  39.     operators = open("operators.txt", "r").readlines()
  40.     keywords = open("keywords.txt", "r").readlines()
  41.  
  42.     text = re.sub(r'"[^"]*"', '', text)
  43.     text = re.sub(r'\'[^\']*\'', '', text)
  44.  
  45.     with open("operatorsOutput.txt", "w") as output:
  46.         for index in range(0, len(keywords)):
  47.             keywords[index] = keywords[index].replace("\n", "")
  48.             if (text.count(keywords[index]) != 0):
  49.                 countOfOperators += text.count(keywords[index])
  50.                 print("<tr><th>" + str(keywords[index]) + "</th><td>" + str(text.count(keywords[index])) + "</td>", file=output)
  51.                 text = re.sub(fr'\s?([\\{str(keywords[index])}])+\s', ' ', text)
  52.                 operatorsDictionary += 1
  53.  
  54.         for index in range(0, len(operators)):
  55.             operators[index] = operators[index].replace("\n", "")
  56.             if (text.count(operators[index]) != 0):
  57.                 countOfOperators += text.count(operators[index])
  58.                 print("<tr><th>" + str(operators[index]) + "</th><td>" + str(text.count(operators[index])) + "</td>", file=output)
  59.                 text = ' '.join(text.replace(operators[index], " ").split())
  60.                 operatorsDictionary += 1
  61.  
  62.     output.close()
  63.  
  64.     with open("operandsOutput.txt", "w") as output:
  65.         operands = sorted(list(set(text.split())))
  66.         text = " " + text + " "
  67.  
  68.         for operand in range(len(operands)):
  69.             operands[operand] = " " + operands[operand] + " "
  70.             print("<tr><th>" + operands[operand] + "</th><td>" + str(text.count(operands[operand])) + "</td>", file=output)
  71.             countOfOperands += text.count(operands[operand])
  72.             operandsDictionary += 1
  73.  
  74.             while (text.count(operands[operand]) != 0) :
  75.                 text = text.replace(operands[operand], ' ')
  76.  
  77.     output.close()
  78. else:
  79.     print("\nPass on correct file paths")
  80.  
  81. eel.init("web")
  82. eel.start("index.html")
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement