Created
March 29, 2021 16:47
-
-
Save 12Me21/b2f8dff8099f9f66656d54333a867ce9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- iterator function, returns: name, message, room, hour, minute | |
function chatlines(file) | |
local name, hour, minute, room | |
return function() | |
local space, name2, hour2, minute2, room2, message | |
local line = file:read() | |
if not line then return end | |
_, _, space, name2, hour2, minute2, room2, message = line:find("^(%s*)([A-Za-z0-9_]-)%[(%d%d):(%d%d)%](.): (.*)$") | |
if space then | |
name, hour, minute, room = name2, tonumber(hour2), tonumber(minute2), room2 | |
else | |
_, _, hour2, minute2, room2, name2, message = line:find("^ %[funmodule%]%[(%d%d):(%d%d)%](.): ([A-Za-z0-9_]-) (.*)$") | |
if hour2 then | |
name, hour, minute, room = name2, tonumber(hour2), tonumber(minute2), room2 | |
elseif line:sub(1,30)==" " then | |
message = line:sub(31) | |
else | |
message = line | |
end | |
end | |
return name, message, room, hour, minute | |
end | |
end | |
-- Example: | |
local filenames = {...} | |
for _,filename in ipairs(filenames) do | |
local _,_,year,month,day = filename:find("(%d%d+)%-(%d%d)%-(%d%d)%.txt$") | |
if year then | |
year = year+2000 | |
print(year,month,day) | |
local f = io.open(filename) | |
for username, message, room, hours, minutes in chatlines(f) do | |
print(username, hours, minutes, room, message) | |
end | |
f:close() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment