Has anyone developed a Python API or Adapter for the RESTful API?
I'm looking to write one as part of a project, but I don't want to invent the wheel.
jamus wrote:Has anyone developed a Python API or Adapter for the RESTful API?
I'm looking to write one as part of a project, but I don't want to invent the wheel.
bschollnick2 wrote:jamus wrote:Has anyone developed a Python API or Adapter for the RESTful API?
I'm looking to write one as part of a project, but I don't want to invent the wheel.
I have some code, but nothing that is too formalized... Are you looking for any specific abilities? What are you trying to manipulate?
# create indigo instance
indigo=IndigoServer("localhost")
#set variable
indigo.var["status"]="running"
#turn off the fan
indigo.dev["fan"].off()
#get state of the motion sensor
print indigo.dev["motion"].state()
#turn on all the lights
def light(n):
return n.find("light")>=0
for device in filter(light,indigo.dev) :
indigo.dev[device].on()
jamus wrote:bschollnick2 wrote:jamus wrote:Has anyone developed a Python API or Adapter for the RESTful API?
I'm looking to write one as part of a project, but I don't want to invent the wheel.
I have some code, but nothing that is too formalized... Are you looking for any specific abilities? What are you trying to manipulate?
I'd like to be able to:
1) Get the list of variables or devices.
2) Query variables
3) Set variables
4) Query state of devices
5) Turn on/off devices
jamus wrote:I think github can help with the group access part.
What error were you getting with ElementTree? I wonder if it's choking on the missing <?xml …>.
bschollnick2 wrote:
Elementtree was returning empty lists for the items, and other components... I tried adding in the Doctype statement, but didn't seem to make any difference... The XML looked clean, so I'm at a loss at why Elementtree was seemingly ignoring it.
jamus wrote:bschollnick2 wrote:
Elementtree was returning empty lists for the items, and other components... I tried adding in the Doctype statement, but didn't seem to make any difference... The XML looked clean, so I'm at a loss at why Elementtree was seemingly ignoring it.
Do you by chance have a snippet of code and XML that exhibits this problem?
def fetch_web_page ( self, web_url):
web_page = urllib.urlopen ( web_url ).readlines()
return web_page
def process_xml_to_data ( self, xml_data ):
# elem = XML(xml_data)
xml_data = '<?xml version="1.0"?>\n' + xml_data
elem = fromstring( xml_data ) #text) # same as XML(xml_data)
print elem.items()
return elem
xml_data = Indigo_server.fetch_web_page ( "http://127.0.0.1:8176/devices/EZIO8SA.xml")
xml_data = "".join (xml_data)
Indigo_server.process_xml_to_data ( xml_data )
def set_server_authentication ( self, username, password):
#
# Password handler - http://www.voidspace.org.uk/python/articles/urllib2.shtml
#
print "Setting auth"
self.password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
print self.server_address
self.username = username
self.password = password
self.password_mgr.add_password(None, self.server_address, self.username, self.password)
self.handler = urllib2.HTTPBasicAuthHandler( self.password_mgr)
self.opener = build_opener( self.handler)
try:
self.opener ( self.server_address )
except:
print "failure"
urllib2.install_opener( self.opener )
#self.auth_handler = urllib2.HTTPBasicAuthHandler()
#self.auth_handler.add_password ( realm=None, uri=self.server_address, user=username, passwd=password)
#self.opener = urllib2.build_opener( self.auth_handler )
#urllib2.install_opener ( self.opener )
def fetch_web_page ( self, web_url):
"""Wrapper around the urllib.urlopen call, that reads the web_url.
Intended for Internal use only.
"""
web_page = urllib2.urlopen ( web_url )
web_page = web_page.readlines()
return web_page
def fetch_xml_page (self, url_to_open ):
url = urllib2.Request (url=url_to_open, data=None)
url_pointer = urllib2.urlopen ( url )
tree = ElementTree.parse (url_pointer )
return tree
bschollnick2 wrote:Hrmph.... I'm being driven crazy here by a small issue with URLLIB2...
Any python assistance would be welcome...
I am attempting to add Basic Authentication to the Restful API wrapper, and it doesn't seem to be working... I've found plenty of examples, and they seem to be identical to my code...
jamus wrote:bschollnick2 wrote:Hrmph.... I'm being driven crazy here by a small issue with URLLIB2...
Any python assistance would be welcome...
I am attempting to add Basic Authentication to the Restful API wrapper, and it doesn't seem to be working... I've found plenty of examples, and they seem to be identical to my code...
The indigo web server expects Digest, not Basic, Authentication. See viewtopic.php?p=24826#p24826
Jamus
Users browsing this forum: No registered users and 12 guests