Comparison

plugins/mod_scansion_record.lua @ 9364:62f9127ab493

mod_scansion_record: Open a related file for header entries Since It's tricky to go back and insert data at the beginning of a file, but `cat blah.sch blah.scs` ought to be fine for now.
author Kim Alvefur <zash@zash.se>
date Sat, 22 Sep 2018 14:36:34 +0200
parent 9363:c4ecaaf66e76
child 9365:acb316319dc0
comparison
equal deleted inserted replaced
9363:c4ecaaf66e76 9364:62f9127ab493
8 local id = require "util.id"; 8 local id = require "util.id";
9 local dm = require "util.datamanager"; 9 local dm = require "util.datamanager";
10 10
11 local record_id = id.medium():lower(); 11 local record_id = id.medium():lower();
12 local record_date = os.date("%Y%b%d"):lower(); 12 local record_date = os.date("%Y%b%d"):lower();
13 local header_file = dm.getpath(record_id, "scansion", record_date, "sch", true);
13 local record_file = dm.getpath(record_id, "scansion", record_date, "scs", true); 14 local record_file = dm.getpath(record_id, "scansion", record_date, "scs", true);
14 15
16 local head = io.open(header_file, "w");
15 local scan = io.open(record_file, "w"); 17 local scan = io.open(record_file, "w");
16 18
17 local function record(string) 19 local function record(string)
18 scan:write(string); 20 scan:write(string);
21 end
22
23 local function record_header(string)
24 head:write(string);
19 end 25 end
20 26
21 local function record_event(session, event) 27 local function record_event(session, event)
22 record(session.scansion_id.." "..event.."\n\n"); 28 record(session.scansion_id.." "..event.."\n\n");
23 end 29 end
72 end); 78 end);
73 79
74 module:hook_global("server-stopping", function () 80 module:hook_global("server-stopping", function ()
75 module:log("info", "Scansion recording available in %s", record_file); 81 module:log("info", "Scansion recording available in %s", record_file);
76 scan:close(); 82 scan:close();
83 head:close()
77 end); 84 end);