can't insert in Variable with elementTree

Posted on
Sat Sep 27, 2014 8:56 am
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

can't insert in Variable with elementTree

Im trying to get the playing state of my Plex Home theater in a variable

this works quoted Indigo lines

Code: Select all
import urllib2
import xml.etree.ElementTree as ET
import indigo

xml = urllib2.urlopen('http://10.0.1.102:32400/status/sessions')
data = xml.read()

root = ET.fromstring(data)

for string in root.findall(".//*[@machineIdentifier='9793cdf6-93ae-4099-9184-6e2a970794f7']"):
   state =  string.attrib['state']
#print state

PlexTheater = indigo.variables[914574013]
indigo.variable.updateValue(PlexTheater, state)

for some reason Indigo can't work with findall
Code: Select all
for string in root.findall(".//*[@machineIdentifier='9793cdf6-93ae-4099-9184-6e2a970794f7']"):


Anybody know how to fix this?

I use this specific line to filter out the state of my main plex system, and leave out all the others that might be running.

all help is welcome!

Posted on
Mon Sep 29, 2014 12:00 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: can't insert in Variable with elementTree

I never use elementTree so I'm afraid I don't know what's going on there.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Sep 29, 2014 12:28 pm
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

Re: can't insert in Variable with elementTree

is there an module that indigo works with that can reads url feeds of xml?

Posted on
Mon Sep 29, 2014 5:21 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: can't insert in Variable with elementTree

Not a single module to do both - you want two different things:

  1. Hit the URL to get the data
  2. Something to decode the XML into something usable by Python

You've got them both, but elementTree doesn't seem to work for you though I suspect it should. Maybe your findall isn't formatted correctly or something (again, I don't use element tree so I can't help there).

We use xml.dom.minidom in the plugin base to parse out the various XML files in a plugin. There are also SAX parsers and the full DOM parser - it just depends on what you like I suppose.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Sep 29, 2014 5:56 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: can't insert in Variable with elementTree

I don't know enough about how your findall is structured, but I can confirm that ElementTree does work within an Indigo Plugin. I use ElementTree within the OWServer plugin.

I ran your URL against my Plex server and when no clients are running, the XML comes up with a single empty tag. When I start a client and rerun the call, I get XML a plenty. Have a look at the plugin.py file -- hopefully, that will get you started. If you're still having trouble, post back and we'll see if we can't get you straightened out.

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Sep 30, 2014 2:14 pm
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

Re: can't insert in Variable with elementTree

Ive got it working by using it as an applescript that runs a shell script with python. the output is put through to a variable in applescript.

Code: Select all
set state to do shell script "python /Users/Server/Documents/plexstate.py"

tell application "IndigoServer"
   if not (variable "PlexTheater" exists) then ¬
      make new variable with properties {name:"PlexTheater", value:state}
   if "PlexTheater" is not equal to (value of variable "PlexTheater") then
      set value of variable "PlexTheater" to state
   end if
end tell


it might not be the best way, but it works. even better, iv posted a little movie that shows how this effects light scenes based on the state.
http://forums.indigodomo.com/viewtopic.php?f=133&t=12661

Posted on
Tue Sep 30, 2014 7:14 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: can't insert in Variable with elementTree

Indigo uses Python 2.5 (calling it like you are is using the latest Python installed on your Mac which is likely newer) so maybe it's a bug in ElementTree in Python 2.5.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 13 guests