-
Notifications
You must be signed in to change notification settings - Fork 1
/
myapp.py
executable file
·44 lines (37 loc) · 906 Bytes
/
myapp.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
import os
import platform
import pyjokes
from flask import Flask
from flask import jsonify
app = Flask(__name__)
@app.route('/')
def index():
result = {"status": "not found"}
return jsonify(result), 404
@app.route('/code')
def code():
_env = os.getenv("CODE", "")
if _env:
result = {"code": _env}
return jsonify(result), 200
else:
result = {"code": "ERROR"}
return jsonify(result), 500
@app.route('/stat')
def stat():
_name = os.getenv("NAME", "")
if _name:
result = {"status": "SUCCESS"}
return jsonify(result), 200
else:
result = {"status": "ERROR"}
return jsonify(result), 503
@app.route('/info')
def info():
_name = os.getenv("NAME", "")
_host = platform.node()
_joke = pyjokes.get_joke()
result = {"name": _name, "host": _host, "joke": _joke}
return jsonify(result), 200
if __name__ == '__main__':
app.run(use_reloader=True, host='0.0.0.0', port=3535, debug=True)