From b5d36da2b6b1a4b07c9d22666ee39284ad9f57e7 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 17 Aug 2015 14:32:05 -0700 Subject: [PATCH] Add /last_aired route For @ask-compu --- README.md | 5 +++++ ponyapi.nim | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 5456f33..61393ed 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,11 @@ objects as defined above. Returns the episode of My Little Pony: Friendship is Magic that will air next. +### `/last_aired` + +Returns the episode of My Little Pony: Friendship is Magic that most recently +aired. + ### `/season/` Returns all information about episodes in the given season number or a `404` diff --git a/ponyapi.nim b/ponyapi.nim index 53df44b..5e7caf9 100644 --- a/ponyapi.nim +++ b/ponyapi.nim @@ -85,6 +85,20 @@ routes: get "/random": resp Http200, myHeaders, pretty(%%episodes.randomChoice(), 4) + get "/last_aired": + var + now = getTime() + ep: Episode + + for epid, episode in pairs[Episode](episodes): + var then = times.fromSeconds(episode.air_date) + + if now < then: + ep = episodes[epid-1] + break + + resp Http200, myHeaders, pretty(%%ep, 4) + get "/season/@snumber": var season: int = @"snumber".parseInt