aboutsummaryrefslogtreecommitdiff
path: root/cgi
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2025-06-24 21:43:00 +0100
committerNat Lasseter <user@4574.co.uk>2025-06-24 21:43:00 +0100
commit8bb5989fc5a77cd86573a7bda51896fd147f3312 (patch)
treea013df33b854befedd1cbd7002f0ea02c34f9baa /cgi
parent58d62a360afc3aad4b372b3c7ef3645aaa6da11e (diff)
[bins] add bins page
Diffstat (limited to 'cgi')
-rw-r--r--cgi/bins.cgi96
-rw-r--r--cgi/home.cgi93
-rwxr-xr-xcgi/user.cgi3
3 files changed, 99 insertions, 93 deletions
diff --git a/cgi/bins.cgi b/cgi/bins.cgi
new file mode 100644
index 0000000..018ed1e
--- /dev/null
+++ b/cgi/bins.cgi
@@ -0,0 +1,96 @@
+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") { "&#x21d3;" }
+ } +
+ $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 { "Our Next Bin Collections" } +
+ next_collection
+ }
+
+# vim: set filetype=ruby:
diff --git a/cgi/home.cgi b/cgi/home.cgi
index f5ad153..b8caad9 100644
--- a/cgi/home.cgi
+++ b/cgi/home.cgi
@@ -1,99 +1,6 @@
-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") { "&#x21d3;" }
- } +
- $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 {
"It is one of the commonest as well as one of the most amusing human idiosyncrasies to imagine that the louder one shouts into the transmitter of a telephone the more perfectly and comfortably does the sound reach the person at the other end. Great numbers of people who in the ordinary affairs of life are tranquil and soft-toned, will habitually yell into a telephone receiver as if they were rooting for the home team. These are, perhaps the same people who think that he who has not the remotest knowledge of English can grasp it without difficulty if only it is shouted at him loudly enough. The theory that prompts vociferousness in the one case is as false as that which prompts it in the other." +
diff --git a/cgi/user.cgi b/cgi/user.cgi
index d6e55d9..1357d65 100755
--- a/cgi/user.cgi
+++ b/cgi/user.cgi
@@ -14,6 +14,7 @@ def toplinks
$cgi.table(class: "toplinks") {
$cgi.tr {
$cgi.td { link("/" , "Home" ) } +
+ $cgi.td { link("/bins" , "Bins" ) } +
$cgi.td { link("/eamit.html" , "eamit" , true) } +
$cgi.td { link("https://git.4574.co.uk/", "Git" , true) } +
$cgi.td { link("/stuff-i-want" , "Stuff I Want" ) }
@@ -89,6 +90,8 @@ $cgi = CGI.new("html5")
case $cgi.path_info
when "/"
page("Home", "User_4574's Lair")
+when "/bins"
+ page("Bins")
when /^\/stuff-i-want/
page("Stuff I Want")
when /^\/bv/