-
Notifications
You must be signed in to change notification settings - Fork 1
/
wsgi.py
executable file
·37 lines (28 loc) · 966 Bytes
/
wsgi.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
#!/usr/bin/python3
import os
from time import time
from flask import Flask
from flask_restx import Resource, Api, reqparse
application = Flask(__name__)
api = Api(application)
parser = reqparse.RequestParser()
parser.add_argument('morning', type=bool, help='Morning greeting')
parser.add_argument('afternoon', type=bool, help='Afternoon greeting')
@api.expect(parser)
@api.route('/hello/<string:name>')
class HelloWorld(Resource):
def get(self, name):
args = parser.parse_args(strict=True)
if args['morning']:
greeting = 'Good morning'
elif args['afternoon']:
greeting = 'Good afternoon'
else:
greeting = 'Hello'
return {greeting: name}
@api.route('/date')
class Time(Resource):
def get(self):
return {'timestamp': time()}
if __name__ == '__main__':
application.run(debug=True, host=os.environ.get('HOST', '127.0.0.1'), port=os.environ.get('FLASK_PORT', 5000))