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.

python newb here

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
scottbakertemp
Posts: 17
Joined: Sun Nov 28, 2010 7:21 pm

python newb here

Post by scottbakertemp »

Can anyone tell me why this doesn't work?

f = open("E:\eventghost web server\test.txt")
data = f.read

if data=="622":
eg.TriggerEvent("HTTP.onkyo.receiver.zone2.poweroff");
if data=="922":
eg.TriggerEvent("HTTP.onkyo.receiver.zone2.poweron");

f.close()
scottbakertemp
Posts: 17
Joined: Sun Nov 28, 2010 7:21 pm

Re: python newb here

Post by scottbakertemp »

this is the error message I get:

Traceback (most recent call last):
Python script "2", line 1, in <module>
f = open("E:\eventghost web server\test.txt")
IOError: [Errno 22] invalid mode ('r') or filename: 'E:\\eventghost web server\test.txt'
jonib
Plugin Developer
Posts: 1328
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: python newb here

Post by jonib »

Try this:

Code: Select all

f = open("E:\\eventghost web server\\test.txt")
jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: python newb here

Post by krambriw »

Unless you are 100% sure that the data content is exactly the string you write (no white space or hidden chars), I would do like this

Code: Select all

f = open("E:\\eventghost web server\\test.txt")
data = f.read

if data.find("622") != -1:
    eg.TriggerEvent("HTTP.onkyo.receiver.zone2.poweroff");

if data.find("922") != -1:
    eg.TriggerEvent("HTTP.onkyo.receiver.zone2.poweron");

f.close()
scottbakertemp
Posts: 17
Joined: Sun Nov 28, 2010 7:21 pm

Re: python newb here

Post by scottbakertemp »

it gave me an error saying: if data.find("622") != -1:
9:06:59 AM AttributeError: 'builtin_function_or_method' object has no attribute 'find'

I noticed in the latest version of event ghost I can put a query registry action followed by a jump to (if last action was successful) action. I can then add that 2 action combination in the same macro to effectively create an if-then-elseif-statement.

This program is REALLY powerful.
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: python newb here

Post by krambriw »

Yes, there was one more error in the code:

Code: Select all

data = f.read
should be

Code: Select all

data = f.read()
Post Reply