diff options
author | Nat Lasseter <user@4574.co.uk> | 2025-05-14 11:19:49 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2025-05-14 11:19:49 +0100 |
commit | 721607120366542241fa566b5e72812861f30eb2 (patch) | |
tree | 3300019cd81c4602b4928086f21e1f8c25bd57fc | |
parent | 5105313a44e653ab5d26a223f76638c4147bb0c2 (diff) |
[toplinks] trialling new waste thing
-rw-r--r-- | cgi/home.cgi | 28 | ||||
-rw-r--r-- | static/styles.css | 18 |
2 files changed, 43 insertions, 3 deletions
diff --git a/cgi/home.cgi b/cgi/home.cgi index 2290340..3e8aeeb 100644 --- a/cgi/home.cgi +++ b/cgi/home.cgi @@ -8,6 +8,11 @@ def next_collection 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"]) @@ -42,6 +47,27 @@ def next_collection out end +def graphic_collection(resp) + events = Array.new(28) { "empty" } + + resp.each { |coll| + days = ((Time.parse(coll["nextCollection"]) - Time.now) / (60*60*24)).ceiling + events[days*2] = coll["service"].downcase + events[days*2 - 1] = coll["service"].downcase + } + + $cgi.table(class: "waste-table") { + $cgi.tr { + tout = "" + (0..27).step(2).each { |i| + tout += $cgi.td(class: "waste-#{events[i]} morning") + tout += $cgi.td(class: "waste-#{events[i+1]} evening") + } + tout + } + } +end + $page = $cgi.div { $cgi.h1 { "Welcome!" } } + $cgi.div { @@ -61,3 +87,5 @@ $page = } + $cgi.p { "From Bell Telephone News, Volume 2, Number 7, Page 18." } } + +# vim: set filetype=ruby: diff --git a/static/styles.css b/static/styles.css index 91f6f98..db2e5ad 100644 --- a/static/styles.css +++ b/static/styles.css @@ -55,17 +55,29 @@ div#quote { font-weight: bold; } -span.waste-refuse { +.waste-refuse { color: white; background-color: black; } -span.waste-recycling { +.waste-recycling { color: white; background-color: darkgreen; } -span.waste-garden { +.waste-garden { color: white; background-color: saddlebrown; } + +table.waste-table { + border-collapse: collapse; + td.morning { + border: 2px solid black; + border-right: none; + } + td.evening { + border: 2px solid black; + border-left: none; + } +} |