From 3a6c6b00eb4c62b24c5e5ca670142ac5a00d7847 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 18 Jun 2024 22:46:31 +0100 Subject: o --- page.cgi | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100755 page.cgi (limited to 'page.cgi') diff --git a/page.cgi b/page.cgi new file mode 100755 index 0000000..6743f91 --- /dev/null +++ b/page.cgi @@ -0,0 +1,120 @@ +#!/usr/bin/env lua + +local foods = require'foods' +local qs = require'qs' + +local days = { + "mon","tue","wed","thu","fri","sat","sun" +} + + +print"Content-type: text/html" +print"" + +local prev_foods = {} +local Q = {} +if os.getenv'REQUEST_METHOD' == 'POST' then + Q = qs.parse_qs(io.read()) + local log = assert(io.open("/home/rebecca/pr/food/LOG", "a+")) + log:write(os.date("%Y-%m-%dT%H:%M:%S")) + for i=0,13 do + local prev_food = assert(tonumber(Q[tostring(i)])) + prev_foods[i] = prev_food + log:write(" "..prev_food) + end + log:write("\n") + log:close() +else + for i=0,13 do + prev_foods[i] = 1 + end +end + +local counts = {} +for i = 0,13 do + counts[i] = (counts[i] or 0) + 1 +end +local start_day = tonumber(Q.start or 1) + +local function ok(fi, si) + return true +end + +local function sel(sel_ix) + local opts = {} + for food_ix,food in ipairs(foods) do + if food_ix == prev_foods[sel_ix] then + table.insert(opts, + '' + ) + elseif ok(food_ix, sel_ix) then + table.insert(opts, + '' + ) + end + end + return '' +end + +local function row(n) + local d = 1+((n+start_day-1)%7) + return '' + .. '' .. days[d] .. '' + .. '' .. sel(2*n) .. '' + .. '' .. sel(2*n+1) .. '' + +end + + +print[[ +
+ + + + + + + + + +]] +for n=0,6 do print(row(n)) end +print[[ +
\lunchdinner
+ +
+
+]] + +local ings = {} +for _,fx in pairs(prev_foods) do + local food = foods[fx] + for k,v in pairs(foods[fx].ing) do + ings[k] = (ings[k] or 0) + v + end +end +local i2 = {} +for k,v in pairs(ings) do + table.insert(i2,k) +end +table.sort(i2) +print'
' + +for _,g in ipairs(i2) do + print('
'..g..'
') + print('
'..ings[g]..'x
') +end +print'
' +for _,g in ipairs(i2) do + print(g..', ') +end -- cgit v1.2.3