format.lua (1173B)
1 json = require "json" 2 fn = "players.json" 3 4 f = io.open(fn, "r") 5 j = f:read("*all") 6 players = json.decode(j) 7 f:close() 8 9 -- x reason 10 -- name 11 -- contact 12 -- x registration 13 -- x deregistration 14 -- observations 15 16 EVENT_FORMAT = " %s %s => %s\n" 17 CONTACT_FORMAT = " aka %s <%s>\n" 18 19 function format(s, d) 20 res = s 21 for k in string.gmatch(s, "{([^{}|]+)}") do 22 if d[k] then 23 res = string.gsub(res, "{"..k.."}", d[k]) 24 else 25 res = string.gsub(res, "{"..k.."}", "??") 26 end 27 end 28 return res 29 end 30 31 for n,h in pairs(players) do 32 io.write("===============\n"..n.."\n") 33 for _,e in ipairs(h) do 34 if e.reason == "s" then 35 f = " ({reason}) {name} <{contact}> ({registration}--now)\n" 36 else 37 f = " ({reason}) {name} <{contact}> ({registration}--{deregistration})\n" 38 end 39 io.write(format(f, e)) 40 if e.observations then 41 io.write(format(" {observations}\n", e)) 42 end 43 -- io.write(string.format(" (%s) %s <%s> (%s--%s)\n", 44 -- e.reason, 45 -- e.name, 46 -- e.contact, 47 -- e.registration, 48 -- e.deregistration or "now")) 49 end 50 io.write("\n") 51 end 52