05.01.2022, 16:52 (This post was last modified: 05.01.2022, 18:19 by pioneersteffen.)
Hi @all,
I want to create a script that gives me a trigger object when a garbage can will be picked up today. Therefore I have all possible pick up dates available in an .ics calendar or I can easiliy convert it to an Excel.
Is there any script / starting point you can help me with?
ICS is a text format so it can be parsed via a script. Can you provide an example ICS that you want to use? Is it stored somewhere where LM can retrieve it automatically?
Attached you can find the example file. I want to check if the actual date is similar to a pick up date in the ics and if yes a group address with the kind of garbage ("Restmüll", "Gelber Sack", etc.) should be send.
The ics I getting from a website as a download and is not stored anywhere.
Here's an example that you can use a starting point. data variable should contain the ICS file contents that you get externally.
First the script parses ICS events into a table. Then it looks for an event with a matching date. summary variable is the summary field (kind of garbage in your case) of the found event or an empty string. Change 1/1/1 as needed and use 250 byte string as the data type of this object.
if not data then
log('request failed', err)
return
end
data = data:split('\n')
events = {}
for _, line in ipairs(data) do
line = line:trim()
if line == 'BEGIN:VEVENT' then
event = {}
elseif line == 'END:VEVENT' then
events[ #events + 1 ] = event
event = nil
elseif event then
pos = line:find(':')
if pos then
key = line:sub(1, pos - 1)
value = line:sub(pos + 1)
event[ key ] = value
end
end
end
now = os.date('%Y%m%d')
summary = ''
for _, event in ipairs(events) do
if event['DTSTART;VALUE=DATE'] == now then
summary = event['SUMMARY']
break
end
end
The content of the variable data. Do I need just to replace „\n“ with the copy and paste text string out of the ics opened by a text editor? I tried to and getting failure messages. Or do you have a recommendation how to convert it?
Would it be also possible to parse it directly from a webcal address?
@admin: If I want to get a message today for a planned pickup tomorrow, how is the modification look like? Sorry for the rookie question I‘ve tried to find a solution via search function without any success.