Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3;added test file #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
# -*- 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')
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(APP, '/')
api.add_resource(API, '/api')

if __name__ == '__main__':
Expand Down
3 changes: 1 addition & 2 deletions joke.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 14 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -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)