12.02.2021, 15:35
(12.02.2021, 15:27)admin Wrote: Run this script to log alerts for the current month and post the result:
Code:date = os.date('*t')
date.month = date.month + 1
date.day, date.hour, date.min, date.sec = 1, 0, 0, 0
ts_end = os.time(date)
date.month = date.month - 1
ts_start = os.time(date)
alerts_table = db:getall('SELECT * FROM alerts where alerttime BETWEEN ? AND ? ORDER BY id DESC', ts_start, ts_end)
-- csv buffer
buffer = {}
-- format csv row
csv = string.format('%q,%q,%q', "ID", "Messaggio", "Data e Ora")
-- add to buffer
table.insert(buffer, csv)
-- add empty line to buffer
table.insert(buffer, "")
-- Loop through alerts_table
for _, alerts in ipairs(alerts_table) do
-- format csv row
csv = string.format('%q,%q,%q', alerts.id, alerts.alert, os.date("%d.%m.%Y %X", alerts.alerttime))
-- add to buffer
table.insert(buffer, csv)
end
res = table.concat(buffer, '\n')
log(res)
this is the result