diff --git a/README.md b/README.md index e802555..c9ffcfe 100644 --- a/README.md +++ b/README.md @@ -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/` Returns all information about episodes in the given season number or a `404` diff --git a/ponyapi.py b/ponyapi.py index f4710f3..3c6dbc6 100644 --- a/ponyapi.py +++ b/ponyapi.py @@ -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/") def season(number): retEpisodes = []