diff options
Diffstat (limited to 'cgi/home.cgi')
-rw-r--r-- | cgi/home.cgi | 41 |
1 files changed, 21 insertions, 20 deletions
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" - "<font color=\"green\">Recycling</font>" - when "GARDEN" - "<font color=\"brown\">Garden Waste</font>" - 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"; "<font color=\"green\">Recycling</font>" + when "GARDEN"; "<font color=\"brown\">Garden Waste</font>" + end + tout += " needs to go out #{dayswords} for collection" if out.empty? + tout += " on #{cdate.strftime("%A")}.<br \>" + out += tout + } + out end $page = |