diff options
Diffstat (limited to 'cgi/home.cgi')
-rw-r--r-- | cgi/home.cgi | 50 |
1 files changed, 2 insertions, 48 deletions
diff --git a/cgi/home.cgi b/cgi/home.cgi index 2290340..b8caad9 100644 --- a/cgi/home.cgi +++ b/cgi/home.cgi @@ -1,54 +1,6 @@ -require "date" -require "json" -require "net/http" -require "time" - -def next_collection - uprn = File.read("../uprn").strip - uri = URI("https://waste-api.york.gov.uk/api/Collections/GetBinCollectionDataForUprn/#{uprn}") - resp = JSON.parse(Net::HTTP.get(uri))["services"].select { |c| Time.parse(c["nextCollection"]) > Time.now }.sort { |a, b| Time.parse(a["nextCollection"]) <=> Time.parse(b["nextCollection"]) } - - out = "" - resp.each { |coll| - cdate = Time.parse(coll["nextCollection"]) - days = ((cdate - Time.now) / (60*60*24)).floor - - dayswords = case days - when 0; "today" - when 1; "tomorrow" - else "in #{days} days" - end - - dateword = Date::DAYNAMES[cdate.wday] - dateord = case cdate.day - when 1,21,31; "st" - when 2,22; "nd" - when 3,23; "rd" - else "th" - end - - tout = "" - tout += "Then " unless out.empty? - tout += case coll["service"] - when "REFUSE"; $cgi.span(class: "waste-refuse") { "General Domestic Waste" } - when "RECYCLING"; $cgi.span(class: "waste-recycling") { "Recycling" } - when "GARDEN"; $cgi.span(class: "waste-garden") { "Garden Waste" } - end - tout += " needs to go out #{dayswords} for collection" if out.empty? - tout += " on #{dateword} the #{cdate.day}#{dateord}." - tout += $cgi.br - out += tout - } - out -end - $page = $cgi.div { $cgi.h1 { "Welcome!" } } + $cgi.div { - $cgi.h2 { "Our Next Bin Collections" } + - $cgi.p { next_collection } - } + - $cgi.div { $cgi.h2 { "Speak Gently Over the Telephone" } + $cgi.blockquote { "It is one of the commonest as well as one of the most amusing human idiosyncrasies to imagine that the louder one shouts into the transmitter of a telephone the more perfectly and comfortably does the sound reach the person at the other end. Great numbers of people who in the ordinary affairs of life are tranquil and soft-toned, will habitually yell into a telephone receiver as if they were rooting for the home team. These are, perhaps the same people who think that he who has not the remotest knowledge of English can grasp it without difficulty if only it is shouted at him loudly enough. The theory that prompts vociferousness in the one case is as false as that which prompts it in the other." + @@ -61,3 +13,5 @@ $page = } + $cgi.p { "From Bell Telephone News, Volume 2, Number 7, Page 18." } } + +# vim: set filetype=ruby: |