forked from fleetman-ci-cd-demo/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
90 lines (68 loc) · 2.04 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from flask import Flask, request, jsonify
app = Flask(__name__)
def is_valid_number(value):
try:
float(value)
return True
except ValueError:
return False
@app.route("/plus", methods=["POST"])
def plus():
data = request.get_json()
a = data.get("a")
b = data.get("b")
if not (is_valid_number(a) and is_valid_number(b)):
return (
jsonify(
{"error": "Invalid input. Both 'a' and 'b' must be valid numbers."}
),
400,
)
result = a + b
return jsonify({"result": result})
@app.route("/minus", methods=["POST"])
def minus():
data = request.get_json()
a = data.get("a")
b = data.get("b")
if not (is_valid_number(a) and is_valid_number(b)):
return (
jsonify(
{"error": "Invalid input. Both 'a' and 'b' must be valid numbers."}
),
400,
)
result = a - b
return jsonify({"result": result})
@app.route("/multiply", methods=["POST"])
def multiply():
data = request.get_json()
a = data.get("a")
b = data.get("b")
if not (is_valid_number(a) and is_valid_number(b)):
return (
jsonify(
{"error": "Invalid input. Both 'a' and 'b' must be valid numbers."}
),
400,
)
result = a * b
return jsonify({"result": result})
@app.route("/divide", methods=["POST"])
def divide():
data = request.get_json()
a = data.get("a")
b = data.get("b")
if not (is_valid_number(a) and is_valid_number(b)):
return (
jsonify(
{"error": "Invalid input. Both 'a' and 'b' must be valid numbers."}
),
400,
)
if b == 0:
return jsonify({"error": "Division by zero is not allowed."}), 400
result = a / b
return jsonify({"result": result})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)