commit e039753a2b3cde0722e35d55b694f613f98de354
Author: Juan F. Meleiro <juan@juanmeleiro.mat.br>
Date: Mon, 19 Jun 2023 12:04:59 -0300
Create reporting script and template
Diffstat:
| A | log.json | | | 2 | ++ |
| A | report | | | 117 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | template.m4 | | | 26 | ++++++++++++++++++++++++++ |
3 files changed, 145 insertions(+), 0 deletions(-)
diff --git a/log.json b/log.json
@@ -0,0 +1 @@
+[]
+\ No newline at end of file
diff --git a/report b/report
@@ -0,0 +1,117 @@
+#!/usr/bin/env lua
+local argparse = require "argparse"
+local json = require "json"
+local path = require "path"
+local fs = require "path.fs"
+
+function die(err, msg)
+ msg = tostring(msg or err)
+ if err then
+ io.stderr:write(msg .. "\n")
+ os.exit(1)
+ end
+end
+
+function decodewith(decoder, fn)
+ die(not path.exists(fn), fn.." does not exist.")
+ die(not path.isfile(fn), fn.." is not a file.")
+ local f, err = io.open(fn, "r")
+ die(err)
+ status, res = xpcall(decoder, die, f:read("a"))
+ f:close()
+ die(not status, res)
+ return res
+end
+
+function encodewith(encoder, fn, data)
+ local f, err = io.open(fn, "w")
+ die(not status, err)
+ status, err = f:write(encoder(data))
+ die(not status, err)
+end
+
+function format(fmt, dict, sett)
+ -- A identifier is
+ -- > any string of Latin letters, Arabic-Indic digits, and
+ -- > underscores, not beginning with a digit and not being a reserved
+ -- > word
+
+ -- local reserved = {
+ -- "and", "break", "do", "else", "elseif", "end", "false", "for",
+ -- "function", "goto", "if", "in", "local", "nil", "not", "or", "repeat",
+ -- "return", "then", "true", "until", "while"
+ -- }
+ res = fmt
+ for s in string.gmatch(fmt, "%{([_a-zA-Z][._a-zA-Z0-9]*)%}") do
+ local value = dict
+ local pref = sett
+ for k in string.gmatch(s, "([_a-zA-Z][_a-zA-Z0-9]*)") do
+ if type(value) == "table" then value = value[k] end
+ if type(pref) == "table" then pref = pref[k] end
+ end
+ if pref and value then string.format(pref, value) end
+ res = fmt.gsub(res, "{"..s.."}", value or "nil")
+ end
+ return res
+end
+
+local parser = argparse("report", "Generate and send the Absurdor report")
+-- parser:argument("input", "Input file.")
+-- parser:option("-o --output", "Output file.", "a.out")
+
+local args = parser:parse()
+
+fn = "log.json"
+log = decodewith(json.decode, fn)
+
+height = 0
+
+for i,e in ipairs(log) do
+ if e.type == "push" then
+ height = height + 1
+ end
+end
+
+height = height % 100
+
+vars = {
+ YYYY = os.date("%Y"),
+ MM = os.date("%m"),
+ DD = os.date("%d"),
+ N = height
+}
+
+defs = ""
+
+for k, v in pairs(vars) do
+ defs = defs .. string.format(" --define=%s=%s", k, v)
+end
+
+tmpname = ".tmp"
+os.execute(string.format("m4 %s template.m4 >> %s", defs, tmpname))
+os.execute(string.format("neomutt -H %s -E", tmpname))
+
+table.insert(log, {
+ timestamp = os.time(),
+ ["type"] = "report",
+ height = height
+})
+
+valid = {
+ Y = true,
+ y = true,
+ n = false,
+ N = false
+}
+
+ans = nil
+while valid[ans] == nil do
+ io.write("Archive report? [Yn] ")
+ ans = io.read(1)
+end
+
+if valid[ans] then
+ encodewith(json.encode, fn, log)
+ os.rename(tmpname, string.format("archive/%s", os.date("%F")))
+end
+
diff --git a/template.m4 b/template.m4
@@ -0,0 +1,26 @@
+changequote(`«', `»')dnl
+Date: esyscmd(«date -R»)dnl
+From: juan <juan@juanmeleiro.mat.br>
+To: <agora-official@agoranomic.org>
+Subject: [Absurdor] The State of the Absurd
+======================================================================
+absurdor: juan The State of the Absurd YYYY-MM-DD
+======================================================================
+
+ ##### _/
+ ####### /
+ ######### /
+ |#########_/
+ / #######/
+ /_ #####/
+ / /O_/ / The Boulder
+ | /_ / is at N
+ /_/\. /
+ // // _/
+ /‘ /‘_/
+ / __`/
+ `_/
+ /
+
+======================================================================
+