11 January, 2016

Json Parsing in Python (Philips Hue Sample)

Import libraries:

import requests
import json
from urllib import urlopen

Here's a class that will print out the names of the scenes:

    ''' AUTORUN METHOD '''
    def __init__(self,master):

        self.apiUrl = "http://192.168.0.11/api"
        self.user = "xxxxxxxxxxxxxxxxxxxxxxxxx"

        self.a = urlopen(self.apiUrl 
            + "/" 
            + self.user 
            + "/" 
            + "scenes").read()
        self.a = json.loads(self.a)
 
        for thing in self.a:
            self.theName = self.a.get( thing ).get('name')
            print self.theName

The function will print out a list of scene names.

No comments: