07.04.2017, 10:16
(07.04.2017, 09:11)akn Wrote: I have the following group addresses:
1/1 / ... - the actual value of meter
1/2 / ... - the value of meter at the beginning of the month
1/3 / ... - the value of consumption for the current month
1/4 / ... - the value of consumption for the previous month
I need a script that once a month, generated a csv file on a local storage. Another script on the scheduled or by event sent this file by email.
thank you in advance
This can be for start:
Once a month:
Code:
actual_value = grp.getvalue('1/1/1')
start_month = grp.getvalue('1/1/1')
current_month = grp.getvalue('1/1/1')
previous_month = grp.getvalue('1/1/1')
labels = "actual_value, start_month, current_month, previous_month/r/n"
meter = labels .. actual_value .. "," .. start_month .. "," .. current_month .. "," .. previous_month .. "/r/n"
storage.set('meter', meter)
Scheduled:
Code:
-- read csv report file
data = storage.get('meter')
-- send file as report.csv with text/csv mime type
res, err = mailattach('someone@example.com', 'Report for current month', 'CSV file attached', 'report.csv', data, 'text/csv')