Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os.path
- import re
- import eel
- countOfOperators = 0
- countOfOperands = 0
- operatorsDictionary = 0
- operandsDictionary = 0
- @eel.expose
- def get_operators():
- operators = open("operatorsOutput.txt", "r").read()
- return operators
- @eel.expose
- def get_operands():
- operators = open("operandsOutput.txt", "r").read()
- return operators
- @eel.expose
- def get_count_of_operators():
- return countOfOperators
- @eel.expose
- def get_count_of_operands():
- return countOfOperands
- @eel.expose
- def get_dictionary_of_operators():
- return operatorsDictionary
- @eel.expose
- def get_dictionary_of_operands():
- return operandsDictionary
- if (os.path.isfile("code.txt") and os.path.isfile("operators.txt")):
- text = open("code.txt", "r").read()
- operators = open("operators.txt", "r").readlines()
- keywords = open("keywords.txt", "r").readlines()
- text = re.sub(r'"[^"]*"', '', text)
- text = re.sub(r'\'[^\']*\'', '', text)
- with open("operatorsOutput.txt", "w") as output:
- for index in range(0, len(keywords)):
- keywords[index] = keywords[index].replace("\n", "")
- if (text.count(keywords[index]) != 0):
- countOfOperators += text.count(keywords[index])
- print("<tr><th>" + str(keywords[index]) + "</th><td>" + str(text.count(keywords[index])) + "</td>", file=output)
- text = re.sub(fr'\s?([\\{str(keywords[index])}])+\s', ' ', text)
- operatorsDictionary += 1
- for index in range(0, len(operators)):
- operators[index] = operators[index].replace("\n", "")
- if (text.count(operators[index]) != 0):
- countOfOperators += text.count(operators[index])
- print("<tr><th>" + str(operators[index]) + "</th><td>" + str(text.count(operators[index])) + "</td>", file=output)
- text = ' '.join(text.replace(operators[index], " ").split())
- operatorsDictionary += 1
- output.close()
- with open("operandsOutput.txt", "w") as output:
- operands = sorted(list(set(text.split())))
- text = " " + text + " "
- for operand in range(len(operands)):
- operands[operand] = " " + operands[operand] + " "
- print("<tr><th>" + operands[operand] + "</th><td>" + str(text.count(operands[operand])) + "</td>", file=output)
- countOfOperands += text.count(operands[operand])
- operandsDictionary += 1
- while (text.count(operands[operand]) != 0) :
- text = text.replace(operands[operand], ' ')
- output.close()
- else:
- print("\nPass on correct file paths")
- eel.init("web")
- eel.start("index.html")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement