diff --git a/app.py b/app.py index b6459a5..73f0fcd 100644 --- a/app.py +++ b/app.py @@ -1,22 +1,23 @@ # -*- coding: utf-8 -*- -from flask import Flask +from flask import Flask,request,jsonify from flask_restful import Resource, Api import joke import sys +import importlib app = Flask(__name__) api = Api(app) -reload(sys) -sys.setdefaultencoding('utf-8') +importlib.reload(sys) -class APP(Resource): +@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: - def get(self): - return {'this is soon to become an awesome->': 'website'} - - - def post(self): jk = joke.getJoke() jk = jk.encode('ascii', 'ignore').decode('ascii') #jk = jk.encode('utf-8') @@ -24,15 +25,11 @@ def post(self): 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(APP, '/') api.add_resource(API, '/api') if __name__ == '__main__': diff --git a/joke.py b/joke.py index 5bcdae9..595a3e6 100644 --- a/joke.py +++ b/joke.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import json -from random import * - +from random import randint def random_digits(joke_count): # Return a joke index between first and last joke in data diff --git a/requirements.txt b/requirements.txt index 0bd7801..9b49a03 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,20 @@ +aniso8601==1.3.0 +certifi==2017.7.27.1 +chardet==3.0.4 +click==6.7 Flask==0.11.1 +Flask-RESTful==0.3.6 gunicorn==19.7.0 httplib2==0.9.2 +idna==2.6 +itsdangerous==0.24 Jinja2==2.8 +MarkupSafe==1.0 +pkg-resources==0.0.0 +python-dateutil==2.6.1 +pytz==2017.2 +requests==2.18.4 +six==1.11.0 +urllib3==1.22 virtualenv==15.1.0 Werkzeug==0.11.10 -flask-restful \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..04c18e4 --- /dev/null +++ b/test.py @@ -0,0 +1,11 @@ +import requests + +# Test Website: +r = requests.get('http://localhost:5000') +print(r.text) +r = requests.post('http://localhost:5000') +print(r.text) + +# Test API: +r = requests.get('http://localhost:5000/api') +print(r.text)