Page 1 of 1
Send content of a file via Blockly
Posted: Wednesday 23 January 2019 17:19
by julien92
Hi,
I would like to know if it possible to send the content of a text file (for instance a log file) within an email, via a Blockly script?
Thanks in advance.
Julien
Re: Send content of a file via Blockly
Posted: Wednesday 23 January 2019 22:32
by waaren
julien92 wrote: ↑Wednesday 23 January 2019 17:19
I would like to know if it possible to send the content of a text file (for instance a log file) within an email, via a Blockly script?
I don't know if it is possible with blockly but in dzVents it would look like
Code: Select all
-- Email text from OS file
return {
on = {
timer = {"every minute" }
},
execute = function(dz)
local function linesFrom(file)
if not dz.utils.fileExists(file) then return 0 end
allLines = {}
for line in io.lines(file) do
allLines[#allLines + 1] = line:gsub('#','บบ') -- the # character is seen as a field separator by domoticz so we need to replace it
end
return allLines
end
local emailaddress = "[email protected]"
local emailSubject = "testSubject"
local osFile = "/etc/init.d/domoticz.sh" -- full qualified filename
local allLines = linesFrom(osFile)
if allLines ~= 0 then
local maxLines = 1000 -- Tested with 1000 lines but YMMV
for i = 0, #allLines, maxLines do -- big steps (at least 1 step)
dz.email(subject,table.concat(allLines,"\\n",i +1,math.min( i + maxLines,#allLines)),emailaddress) -- When more then maxLines split in multiple Emails
end
else
dz.email(emailSubject,"Non existent file",emailaddress) -- Wrong filename ??
end
end
}