Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

How to split event sting with unknown number of splits?

If you have a question or need help, this is the place to be.
Post Reply
therealbiglou
Experienced User
Posts: 126
Joined: Sat May 19, 2012 4:33 am

How to split event sting with unknown number of splits?

Post by therealbiglou »

I have my Amazon Echo send events to EventGhost with voice commands. What I would like to do is be able to say, "Alexa, tell the TV to turn on and watch NBC". This would then create the event:

Code: Select all

HTTP.EchoToEG [u'turn on and watch NBC']
I have a script take this and make an action with a unique sting:

Code: Select all

Main.EchoToEG.turn on and watch NBC
What is the best way to take the word "and" and make the string split into multiple events with the caveat that I don't know how many "ands" there will be. For instance, I may say, "Alexa, tell the TV to turn on and watch Fox Sports Midwest and turn the volume up."

I would then want 3 events:
  • Main.EchoToEG.turn on
  • Main.EchoToEG.watch Fox Sports Midwest
  • Main.EchoToEG.turn the volume up
Any help is greatly appreciated!
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: How to split event sting with unknown number of splits?

Post by kgschlosser »

if you only want to split the payload on the word 'and' and create never events based in this.

this is all set up based on the event posted. the payload has be to surrounded by []'s and the suffix you want has to be the first item listed between the []'s otherwise this will fail. if you run into an issue with this working let me know...

This will also account for the possibility that the word 'and' is not in the string and it will still create an event. I am not sure if you only wanted things with the word and or not so i didn't do anything to check it just assumes all string you will want converted whether it has an 'and' or not.

the reason for the ' and ' in the split. i put the space before and after because when doing a split it will remove the actual string you are using to make the split.. so there is no need to have the spaces at the beginning, end or both of an event. so by adding them to the split search. the spaces are removed as well

you have to copy and paste the code below into an action called python script and put the event you want to have trigger it before it.
and if spaces are not a worry and you only need it for the event and not the text. and would like to have the event look good remove the # before the first item

I put in a couple options for ya so read the script.. it will tell you what to do

Code: Select all

suffixes= eg.event.payload[0].split(' and ')

for suffix in suffixes:
    # the 2 options below will give you a "pretty" event suffix this is if you 
    # are not using the actual suffix for anything other then just triggering
    # an event

    # remove the # before the next line if you would like all the first letters
    # in the suffix to be capital but not to mess with anything that might be
    # like NBC it will stay the same

    #suffix = ' '.join(list(word[0].upper() + word[1:] for word in suffix.split(' ')))

    # remove the # from the next line if you would like to remove all of the 
    # spaces from the suffix

    #suffix = suffix.replace(' ', '')

    # swap the # between these 2 depending if you want to have the "Main."
    # in your event

    eg.TriggerEvent(prefrix='EchoToEG', suffix=suffix)
    #eg.TriggerEvent(suffix='EchoToEG.' + suffix)

If you like the work I have been doing then feel free to Image
therealbiglou
Experienced User
Posts: 126
Joined: Sat May 19, 2012 4:33 am

Re: How to split event sting with unknown number of splits?

Post by therealbiglou »

Thank you! That worked wonderfully! I really appreciate your help!!!
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: How to split event sting with unknown number of splits?

Post by kgschlosser »

no worries m8, that's why we are here

:-D
If you like the work I have been doing then feel free to Image
Post Reply