Use of Event wildcard in code ?

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
Snowbird
Experienced User
Posts: 170
Joined: Fri Jul 03, 2009 10:04 am

Use of Event wildcard in code ?

Post by Snowbird » Sat Dec 23, 2017 5:49 pm

Hello,

I'm struggling a bit, I don't know how to use the wildcard with an event :

Code: Select all

if eg.event.string == "System.PowerProfile.*" :
    my code here
I want it to match all these events :
System.PowerProfile.HighPerformance
System.PowerProfile.PowerSaver
System.PowerProfile.Balanced

I've checked the wiki but there's no mention about the use of wildcard directly in the code :
http://www.eventghost.net/mediawiki/ind ... _Events.29

how can I do this ?
Thank you

yokel22
Experienced User
Posts: 161
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: Use of Event wildcard in code ?

Post by yokel22 » Sat Dec 23, 2017 7:51 pm

I'm not sure if what you want is possible from script. You can use startswith() or the re module to accomplish this though.

Code: Select all

string = "System.PowerProfile."
match = eg.event.string.startswith(string)
if match == True:
     # wildcard was met, execute code
     print 'wildcard'

User avatar
kgschlosser
Site Admin
Posts: 3224
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Use of Event wildcard in code ?

Post by kgschlosser » Sun Dec 24, 2017 1:11 am

Code: Select all


import fnmatch

if fnmatch.fnmatchcase(eg.event.string, 'Some.*.Event.?ame'):
    # do your code here
    
or this if you are looking for a specific phrase in the eg.event.string

Code: Select all

if 'Some.Event' in eg.event.string:
    # do your code here
If you like the work I have been doing then feel free to Image

Snowbird
Experienced User
Posts: 170
Joined: Fri Jul 03, 2009 10:04 am

Re: Use of Event wildcard in code ?

Post by Snowbird » Sun Dec 24, 2017 10:21 am

Thanks to both of you ;)

I picked kg method, it worked right away !

PS. Maybe it's worth adding this example in the wiki ? it could be helpful to others I think.

Merry X-mas everyone ! :)

Post Reply