absurdor

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit f44093575e47eee216e02cd689f1d5b066bf36a0
parent 7106ca0c959fd9dd440ab6131388f4ba00bec44e
Author: Juan F. Meleiro <juan@juanmeleiro.mat.br>
Date:   Thu,  9 Nov 2023 07:55:14 -0300

Change log to jsonl

Diffstat:
Mabsurdor | 35+++++++++++++++++++++++++++++++----
Mlog.json | 38++++++++++++++++++++++++++++++++++++--
2 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/absurdor b/absurdor @@ -4,7 +4,7 @@ local json = require "json" local path = require "path" local fs = require "path.fs" local date = require "date" -local pprint = require "pprint" +local pprint = require("pprint").pprint function die(err, msg) msg = tostring(msg or err) @@ -35,7 +35,7 @@ function decodewith(decoder, fn) 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')) + status, res = xpcall(decoder, die, f) f:close() die(not status, res) return res @@ -73,6 +73,33 @@ function format(fmt, dict, sett) return res end +function is_valid_entry(e) + return ( + (e.what ~= nil) and + (e.when ~= nil) and + (e.what ~= "push" or e.who ~= nil) and + (e.what ~= "report" or e.height ~= nil) + ) +end + +function parse_jsonl(f) + local log = {} + for l in f:lines() do + local e = json.decode(l) + die(not is_valid_entry(e), string.format("Invalid log entry:\n %s", l)) + table.insert(log, e) + end + return log +end + +function write_jsonl(l) + local res = "" + for _,v in ipairs(l) do + res = res .. json.encode(v) .. "\n" + end + return res +end + function fmt_event(e) date = os.date("%Y-%m-%d %H:%M:%S %z", e.when) args = {ts = date} @@ -111,7 +138,7 @@ parser:command("log", "Display log") local args = parser:parse() fn = "log.json" -log = decodewith(json.decode, fn) +log = decodewith(parse_jsonl, fn) if args.command == "report" then @@ -235,5 +262,5 @@ elseif args.command == "log" then end end -encodewith(json.encode, fn, log) +encodewith(write_jsonl, fn, log) diff --git a/log.json b/log.json @@ -1 +1,36 @@ -[{"height":0,"what":"report","when":1687186898},{"when":1687483775,"what":"push","who":"4st"},{"height":1,"what":"report","when":1687783602},{"height":1,"what":"report","when":1688411251},{"when":1688997918,"what":"push","who":"juan"},{"height":2,"what":"report","when":1689001176},{"height":2,"what":"report","when":1689965374},{"height":2,"what":"report","when":1690248734},{"when":1690814390,"what":"push","who":"juan"},{"height":3,"what":"report","when":1690814458},{"when":1690842943,"what":"push","who":"snail"},{"height":4,"what":"report","when":1691422342},{"height":4,"what":"report","when":1692015498},{"height":4,"what":"report","when":1692643133},{"when":1693175927,"what":"push","who":"snail"},{"height":5,"what":"report","when":1693231987},{"height":5,"what":"report","when":1693918103},{"height":5,"what":"report","when":1693918207},{"height":0,"what":"report","when":1694441365},{"when":1694441716,"what":"push","who":"juan","where":"20230911141516.fg7w76yg5yvuavhr@grimnir"},{"height":1,"what":"report","when":1695040187},{"height":0,"what":"report","when":1695655471},{"when":1695655510,"what":"push","who":"juan"},{"height":1,"what":"report","when":1696278128},{"when":1696278126,"what":"push","who":"juan","where":"e3siqismfpl6bxsvqppizt4it52jpnyn4laayp6lo7vkqbub74@ybz7yynnllio"},{"when":1696591280,"what":"push","who":"snail","where":"CAFDWCJa3n0G0-L68xN-Q23Z_-AEeQiKcqf0-K4cnZrjRPdzjYQ@mail.gmail.com"},{"when":1697257473,"what":"push","who":"kiako","where":"7d233f1d-ba60-4ffa-9a2d-5867441f5228@gmail.com"},{"height":4,"what":"report","when":1697462276},{"when":1697794974,"what":"push","who":"snail","where":"CAFDWCJZ9V6e+RMdZg639WvhcQ2v=PxM_Z9K2wNG7yDC2ymra1g@mail.gmail.com"},{"height":5,"what":"report","when":1698073095},{"when":1698612663,"what":"push","who":"snail","where":"CAFDWCJZygQrTjYe0qz1KLOK3JS3HmBv64h69mXSjGOwbPVP_cg@mail.gmail.com"},{"height":6,"what":"report","when":1698694564},{"height":6,"what":"report","when":1699285556},{"when":1699293000,"what":"push","who":"kiako","where":"33255be4-743b-4ee0-ae4b-ac35d2c3ca1d@gmail.com"},{"when":1699445073,"what":"push","who":"snail","where":"CAFDWCJaZVKE2AJJpe-w5c8W6xeDYGnE3AV6=TbWxEHE7GqoOzQ@mail.gmail.com"},{"when":1699448836,"what":"push","who":"juan","where":"f4kaxlwpvu52qzvqgrhunlj3r2ycom7k2apyeb6n4zeyukl6te@bq76vycwlw4r"}] -\ No newline at end of file +{"what":"report","height":0,"when":1687186898} +{"what":"push","who":"4st","when":1687483775} +{"what":"report","height":1,"when":1687783602} +{"what":"report","height":1,"when":1688411251} +{"what":"push","who":"juan","when":1688997918} +{"what":"report","height":2,"when":1689001176} +{"what":"report","height":2,"when":1689965374} +{"what":"report","height":2,"when":1690248734} +{"what":"push","who":"juan","when":1690814390} +{"what":"report","height":3,"when":1690814458} +{"what":"push","who":"snail","when":1690842943} +{"what":"report","height":4,"when":1691422342} +{"what":"report","height":4,"when":1692015498} +{"what":"report","height":4,"when":1692643133} +{"what":"push","who":"snail","when":1693175927} +{"what":"report","height":5,"when":1693231987} +{"what":"report","height":5,"when":1693918103} +{"what":"report","height":5,"when":1693918207} +{"what":"report","height":0,"when":1694441365} +{"what":"push","when":1694441716,"where":"20230911141516.fg7w76yg5yvuavhr@grimnir","who":"juan"} +{"what":"report","height":1,"when":1695040187} +{"what":"report","height":0,"when":1695655471} +{"what":"push","who":"juan","when":1695655510} +{"what":"report","height":1,"when":1696278128} +{"what":"push","when":1696278126,"where":"e3siqismfpl6bxsvqppizt4it52jpnyn4laayp6lo7vkqbub74@ybz7yynnllio","who":"juan"} +{"what":"push","when":1696591280,"where":"CAFDWCJa3n0G0-L68xN-Q23Z_-AEeQiKcqf0-K4cnZrjRPdzjYQ@mail.gmail.com","who":"snail"} +{"what":"push","when":1697257473,"where":"7d233f1d-ba60-4ffa-9a2d-5867441f5228@gmail.com","who":"kiako"} +{"what":"report","height":4,"when":1697462276} +{"what":"push","when":1697794974,"where":"CAFDWCJZ9V6e+RMdZg639WvhcQ2v=PxM_Z9K2wNG7yDC2ymra1g@mail.gmail.com","who":"snail"} +{"what":"report","height":5,"when":1698073095} +{"what":"push","when":1698612663,"where":"CAFDWCJZygQrTjYe0qz1KLOK3JS3HmBv64h69mXSjGOwbPVP_cg@mail.gmail.com","who":"snail"} +{"what":"report","height":6,"when":1698694564} +{"what":"report","height":6,"when":1699285556} +{"what":"push","when":1699293000,"where":"33255be4-743b-4ee0-ae4b-ac35d2c3ca1d@gmail.com","who":"kiako"} +{"what":"push","when":1699445073,"where":"CAFDWCJaZVKE2AJJpe-w5c8W6xeDYGnE3AV6=TbWxEHE7GqoOzQ@mail.gmail.com","who":"snail"} +{"what":"push","when":1699448836,"where":"f4kaxlwpvu52qzvqgrhunlj3r2ycom7k2apyeb6n4zeyukl6te@bq76vycwlw4r","who":"juan"}