-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathapp.py
36 lines (29 loc) · 845 Bytes
/
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
# -*- coding: utf-8 -*-
from flask import Flask,request,jsonify
from flask_restful import Resource, Api
import joke
import sys
import importlib
app = Flask(__name__)
api = Api(app)
importlib.reload(sys)
@app.route('/',methods=['POST','GET'])
@app.route('/index', methods=['POST','GET'])
def index():
if request.method == "GET":
response = "this is soon to become an awesome-> : website"
return jsonify(response)
else:
jk = joke.getJoke()
jk = jk.encode('ascii', 'ignore').decode('ascii')
#jk = jk.encode('utf-8')
return jk
class API(Resource):
def get(self):
jk = joke.getJoke()
jk = jk.encode('ascii', 'ignore').decode('ascii')
# jk = jk.encode('utf-8')
return jk
api.add_resource(API, '/api')
if __name__ == '__main__':
app.run(debug=True)