From 8bb5989fc5a77cd86573a7bda51896fd147f3312 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Tue, 24 Jun 2025 21:43:00 +0100 Subject: [bins] add bins page --- cgi/home.cgi | 93 ------------------------------------------------------------ 1 file changed, 93 deletions(-) (limited to 'cgi/home.cgi') diff --git a/cgi/home.cgi b/cgi/home.cgi index f5ad153..b8caad9 100644 --- a/cgi/home.cgi +++ b/cgi/home.cgi @@ -1,98 +1,5 @@ -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"]) } - - words_collection(resp) + - graphic_collection(resp) -end - -def words_collection(resp) - 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 - } - $cgi.p { out } -end - -def graphic_collection(resp) - events = Array.new(30) { "empty" } - - resp.each { |coll| - days = ((Time.parse(coll["nextCollection"]) - Time.now) / (60*60*24)).ceil - events[days*2] = coll["service"].downcase - events[days*2 - 1] = coll["service"].downcase - } - - $cgi.table(class: "waste-table") { - $cgi.tr { - (Time.now.hour > 12 ? $cgi.td : "") + - $cgi.td(class: "arrow") { "⇓" } - } + - $cgi.tr { - tout = "" - (0..29).step(2).each { |i| - tout += $cgi.td(class: "waste-#{events[i]} morning") - tout += $cgi.td(class: "waste-#{events[i+1]} evening") - } - tout - } + - $cgi.tr { - tout = "" - wdays = %w(Su Mo Tu We Th Fr Sa) - (0..14).each { |i| - tout += $cgi.td(colspan: 2) { wdays[(Time.now + (i * 60*60*24)).wday] } - } - tout - } + - $cgi.tr { - tout = "" - (0..14).each { |i| - tout += $cgi.td(colspan: 2) { (Time.now + (i * 60*60*24)).day } - } - tout - } - } -end - $page = $cgi.div { $cgi.h1 { "Welcome!" } } + - $cgi.div { - $cgi.h2 { "Our Next Bin Collections" } + - next_collection - } + $cgi.div { $cgi.h2 { "Speak Gently Over the Telephone" } + $cgi.blockquote { -- cgit v1.2.3