Add /newest route and document it
This commit is contained in:
parent
a7812b9b5b
commit
04988f9954
|
@ -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
|
Returns all information about all episodes. This returns an array of Episode
|
||||||
objects as defined above.
|
objects as defined above.
|
||||||
|
|
||||||
|
### `/newest`
|
||||||
|
|
||||||
|
Returns the episode of My Little Pony: Friendship is Magic that will air next.
|
||||||
|
|
||||||
### `/season/<number>`
|
### `/season/<number>`
|
||||||
|
|
||||||
Returns all information about episodes in the given season number or a `404`
|
Returns all information about episodes in the given season number or a `404`
|
||||||
|
|
13
ponyapi.py
13
ponyapi.py
|
@ -1,5 +1,7 @@
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from flask import Flask, abort, jsonify, request, redirect
|
from flask import Flask, abort, jsonify, request, redirect
|
||||||
|
|
||||||
# An Episode is constructed as such:
|
# An Episode is constructed as such:
|
||||||
|
@ -40,6 +42,17 @@ def hello():
|
||||||
def all_episodes():
|
def all_episodes():
|
||||||
return jsonify(episodes=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>")
|
@app.route("/season/<number>")
|
||||||
def season(number):
|
def season(number):
|
||||||
retEpisodes = []
|
retEpisodes = []
|
||||||
|
|
Loading…
Reference in New Issue