diff options
Diffstat (limited to 'cgi/home.cgi')
-rw-r--r-- | cgi/home.cgi | 28 |
1 files changed, 28 insertions, 0 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: |