From 1f5c5647e69fe04b98fd0b1af193880a00e9114e Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 10 Mar 2025 20:05:03 +0000 Subject: Even even better waste sentence --- cgi/home.cgi | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'cgi/home.cgi') diff --git a/cgi/home.cgi b/cgi/home.cgi index fdde816..b6dafb6 100644 --- a/cgi/home.cgi +++ b/cgi/home.cgi @@ -4,29 +4,30 @@ require "time" def next_collection uri = URI("https://waste-api.york.gov.uk/api/Collections/GetBinCollectionDataForUprn/***REMOVED***") - 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"]) }[0] + 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"]) } - cdate = Time.parse(resp["nextCollection"]) - days = ((cdate - Time.now) / (60*60*24)).floor + 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 + dayswords = case days + when 0; "today" + when 1; "tomorrow" + else "in #{days} days" + end - case resp["service"] - when "REFUSE" - "Refuse" - when "RECYCLING" - "Recycling" - when "GARDEN" - "Garden Waste" - end + - " needs to go out #{dayswords} for collection on #{cdate.strftime("%A")}." + tout = "Then " unless out.empty? + tout += case coll["service"] + when "REFUSE"; "General Domestic Waste" + when "RECYCLING"; "Recycling" + when "GARDEN"; "Garden Waste" + end + tout += " needs to go out #{dayswords} for collection" if out.empty? + tout += " on #{cdate.strftime("%A")}.
" + out += tout + } + out end $page = -- cgit v1.2.3