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

handled edge cases || refactored the code || handled responses of end… #31

Open
wants to merge 1 commit 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
10 changes: 2 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,16 @@
class APP(Resource):

def get(self):
# function is called when the user makes a GET request to / endpoint.
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):
# function is called when the user makes a GET request to /api endpoint.
jk = joke.getJoke()
jk = jk.encode('ascii', 'ignore').decode('ascii')
# jk = jk.encode('utf-8')
return jk


Expand Down
Binary file added app.pyc
Binary file not shown.
13 changes: 8 additions & 5 deletions joke.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

def random_digits(joke_count):
# Return a joke index between first and last joke in data
return randint(1, joke_count)
if joke_count and joke_count >= 1:
return [True,randint(1, joke_count)]
return [False,"json dataset is empty"]

def get_joke():
def getJoke():
# Return random joke
with open('data.json') as data_file:
data = json.load(data_file)
joke = data[random_digits(len(data))]
print joke
return joke
joke = random_digits(len(data))
if joke[0]:
return data[joke[1]]
return joke[1]
Binary file modified joke.pyc
Binary file not shown.