#!/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[[
\ lunch dinner


]] 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