Skip to content

Commit

Permalink
Merge pull request #12 from megasanjay/sourcery/main
Browse files Browse the repository at this point in the history
Sourcery refactored main branch
  • Loading branch information
Sanjay Soundarajan authored May 25, 2022
2 parents eae2472 + 5e045cc commit d55a6ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/pyflask/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class HelloWorld(Resource):
@api.response(200, "Success")
@api.response(400, "Validation Error")
def get(self):
response = "Server active!!"
return response
return "Server active!!"


# Request parser documentation can be found here: https://flask-restx.readthedocs.io/en/latest/parsing.html
Expand Down Expand Up @@ -58,10 +57,8 @@ def post(self):

args = parser.parse_args()
formula = args["expression"]
response = str(calc(formula))

# restx will automatically jsonify dictionaries. You don't need to import the jsonify method from flask
return response
return str(calc(formula))


# 5000 is the flask default port. You can change it to something else if you want.
Expand Down
8 changes: 4 additions & 4 deletions src/pyflask/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def calc(s):
if isUnary:
opStk.append('#')
else:
while (len(opStk) > 0):
while opStk:
if ((getAssoc(s[i]) == "LEFT" and getPrec(s[i]) <= getPrec(opStk[-1])) or
(getAssoc(s[i]) == "RIGHT" and getPrec(s[i]) < getPrec(opStk[-1]))):
op = opStk.pop()
Expand All @@ -75,7 +75,7 @@ def calc(s):
opStk.append(s[i])
isUnary = True
else:
while (len(opStk) > 0):
while opStk:
op = opStk.pop()
if (op == '('):
break
Expand All @@ -87,7 +87,7 @@ def calc(s):
numStk.append(getBin(op, a, b))
i += 1

while (len(opStk) > 0):
while opStk:
op = opStk.pop()
if op == '#':
numStk.append(-numStk.pop())
Expand All @@ -114,5 +114,5 @@ def calc(s):
]
for s in ss:
res = calc(s)
print('{} = {}'.format(res, s))
print(f'{res} = {s}')

0 comments on commit d55a6ff

Please sign in to comment.