aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cgi/bins.cgi96
-rw-r--r--cgi/home.cgi50
-rwxr-xr-xcgi/user.cgi36
-rw-r--r--static/styles.css48
4 files changed, 154 insertions, 76 deletions
diff --git a/cgi/bins.cgi b/cgi/bins.cgi
new file mode 100644
index 0000000..fb959f1
--- /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.h2 { "Our Next Bin Collections" } +
+ next_collection
+ }
+
+# vim: set filetype=ruby:
diff --git a/cgi/home.cgi b/cgi/home.cgi
index 2290340..b8caad9 100644
--- a/cgi/home.cgi
+++ b/cgi/home.cgi
@@ -1,54 +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"]) }
-
- 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
- }
- out
-end
-
$page =
$cgi.div { $cgi.h1 { "Welcome!" } } +
$cgi.div {
- $cgi.h2 { "Our Next Bin Collections" } +
- $cgi.p { 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." +
@@ -61,3 +13,5 @@ $page =
} +
$cgi.p { "From Bell Telephone News, Volume 2, Number 7, Page 18." }
}
+
+# vim: set filetype=ruby:
diff --git a/cgi/user.cgi b/cgi/user.cgi
index e1c4d70..6092552 100755
--- a/cgi/user.cgi
+++ b/cgi/user.cgi
@@ -2,26 +2,21 @@
require 'cgi'
-def llink(href, text)
- if $cgi.path_info == href
- $cgi.a(href) { "[ #{text} &#x21d3; ]" }
+def link(href, text, remote = false)
+ if remote
+ $cgi.a(href: href, target: "_blank") { "[ #{text} &#x21d7; ] " }
else
- $cgi.a(href) { "[ #{text} ]" }
+ $cgi.a(href: href) { "[ #{text} ] " }
end
end
-def rlink(href, text)
- $cgi.a(href: href, target: "_blank") { "[ #{text} &#x21d7; ] " }
-end
-
def toplinks
- $cgi.table(id: "toplinks") {
- $cgi.tr {
- $cgi.td { llink("/" , "Home" ) } +
- $cgi.td { llink("/eamit.html" , "Eamit" ) } +
- $cgi.td { rlink("https://git.4574.co.uk/", "Git" ) } +
- $cgi.td { llink("/stuff-i-want" , "Stuff I Want") }
- }
+ $cgi.ul(class: "toplinks") {
+ $cgi.li { link("/" , "Home" ) } +
+ $cgi.li { link("/bins" , "Bins" ) } +
+ $cgi.li { link("/eamit.html" , "eamit" , true) } +
+ $cgi.li { link("https://git.4574.co.uk/", "Git" , true) } +
+ $cgi.li { link("/stuff-i-want" , "Stuff I Want" ) }
}
end
@@ -31,12 +26,13 @@ def rquote
"User_4574 uses Linux, and loves life.",
"User_4574 shall arrange the blocks and toil, for ever and a day.",
"User_4574 likes the number 7.",
- "ex scientia veritas",
+ "ex scientia, tyrannis",
"User_4574 will blow things up for money.",
"User_4574 dreams it possible.",
"(define (! ?) (? ?)) (! !)",
"User_4574 lets her pain fade down.",
"User_4574 maintains vigilance during disablement conditions.",
+ "THIS TERMINAL IS LOGGED ON TO THE NETWORK SOLICITOR.",
"User_4574 is established on the localiser.",
"Memetic Hazard.",
"Every six months User_4574 checks the oil level of the drive housing, and if necessary tops up with IBM 15 to the level of the inspection hole.",
@@ -76,8 +72,10 @@ def page(title, jumbotitle = title)
$cgi.link(rel: "stylesheet", href: "styles.css")
} +
$cgi.body {
- $cgi.h1("class" => "jumbo") { jumbotitle } +
- $cgi.div { toplinks } +
+ $cgi.div(class: "pagetop") {
+ $cgi.h1(class: "jumbo") { jumbotitle } +
+ toplinks
+ } +
$page +
$cgi.div(id: "quote") { rquote }
}
@@ -90,6 +88,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/
diff --git a/static/styles.css b/static/styles.css
index a15f136..aacacd2 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -6,8 +6,12 @@ h1 {
margin: 0;
}
+div.pagetop {
+ padding: 0;
+ background-image: linear-gradient(darkgreen, honeydew);
+}
+
h1.jumbo {
- background-image: linear-gradient(green, darkgreen);
color: white;
text-align: center;
font-size: 10em;
@@ -26,13 +30,16 @@ div {
padding: 1em;
}
-table#toplinks {
- width: 100%;
- td {
- width: 1%;
- text-align: center;
+ul.toplinks {
+ margin: 0;
+ padding: 0;
+ text-align: center;
+ list-style-type: none;
+ li {
+ padding: 5px 20px;
+ display: inline-block;
a {
- font-size: 2em;
+ font-size: 1.75em;
color: green;
text-decoration: none;
}
@@ -51,17 +58,38 @@ 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 {
+ width: 15px;
+ height: 15px;
+ text-align: center;
+ }
+ td.morning {
+ border: 2px solid black;
+ border-right: 1px dotted grey;
+ }
+ td.evening {
+ border: 2px solid black;
+ border-left: 1px dotted grey;
+ opacity: 50%;
+ }
+ td.arrow {
+ font-size: 2em;
+ }
+}