diff --git a/app.py b/app.py index b6459a5..1606ac8 100644 --- a/app.py +++ b/app.py @@ -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 diff --git a/app.pyc b/app.pyc new file mode 100644 index 0000000..5f17808 Binary files /dev/null and b/app.pyc differ diff --git a/joke.py b/joke.py index 5bcdae9..68a52a8 100644 --- a/joke.py +++ b/joke.py @@ -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] \ No newline at end of file diff --git a/joke.pyc b/joke.pyc index f665d7f..e0f82c9 100644 Binary files a/joke.pyc and b/joke.pyc differ