Add /newest route and document it

This commit is contained in:
Christine Dodrill 2015-08-09 14:09:24 -07:00
parent a7812b9b5b
commit 04988f9954
2 changed files with 17 additions and 0 deletions

View File

@ -58,6 +58,10 @@ $ curl http://ponyapi.apps.xeserv.us/season/1/episode/1
Returns all information about all episodes. This returns an array of Episode
objects as defined above.
### `/newest`
Returns the episode of My Little Pony: Friendship is Magic that will air next.
### `/season/<number>`
Returns all information about episodes in the given season number or a `404`

View File

@ -1,5 +1,7 @@
import datetime
import os
import random
from flask import Flask, abort, jsonify, request, redirect
# An Episode is constructed as such:
@ -40,6 +42,17 @@ def hello():
def all_episodes():
return jsonify(episodes=episodes)
@app.route("/newest")
def newest_episode():
now = datetime.datetime(2006, 1, 4)
now = now.now()
for episode in episodes:
if now.fromtimestamp(episode["air_date"]) > now:
return jsonify(episode=episode)
abort(500)
@app.route("/season/<number>")
def season(number):
retEpisodes = []