Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 10 additions & 12 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# -*- 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)

importlib.reload(sys)


reload(sys)
sys.setdefaultencoding('utf-8')

class APP(Resource):
def get(self):
return {'this is soon to become an awesome->': 'website'}

def post(self):
@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')
Expand All @@ -30,7 +29,6 @@ def get(self):
# jk = jk.encode('utf-8')
return jk

api.add_resource(APP, '/')
api.add_resource(API, '/api')

if __name__ == '__main__':
Expand Down
10 changes: 6 additions & 4 deletions joke.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# -*- coding: utf-8 -*-
import json
from random import *
from random import randint

def random_digits():
range_start = 1
range_end = 545
with open('data.json') as data_file:
data = json.load(data_file)
range_end = len(data)
return randint(range_start, range_end)

def getJoke():
with open('data.json') as data_file:
data = json.load(data_file)
joke = data[random_digits()]
print joke
return joke
return joke
15 changes: 13 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
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
Jinja2==2.8
virtualenv==15.1.0
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
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)