Skip to content

Instantly share code, notes, and snippets.

@chaeplin
Last active July 13, 2016 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaeplin/7429af33aff4d922aa969b47ae8ee988 to your computer and use it in GitHub Desktop.
Save chaeplin/7429af33aff4d922aa969b47ae8ee988 to your computer and use it in GitHub Desktop.
nest.py
#!/usr/bin/env python2
# encoding: utf-8
import sys
import time
import httplib
import json
import re
url = "api.home.nest.com"
devel_url = "developer-api.nest.com"
access_token = ""
# get device id
path_devel = "/devices/thermostats?auth=" + access_token
conn_devel = httplib.HTTPSConnection(devel_url)
conn_devel.request("GET", path_devel)
conn_devel_httpResponse = conn_devel.getresponse()
#firebase
path_firebase = conn_devel_httpResponse.getheader('Location')
match = re.search('https:\/\/(.*):(.*)\/(.*)\/(.*)$', path_firebase)
if match:
firebase_url = match.group(1)
firebase_port = match.group(2)
firbase_path1 = match.group(3)
firbase_path2 = match.group(4)
firbase_path = "/" + firbase_path1 + "/" + firbase_path2
else:
sys.exit("Can't get firebase url")
firebase_devel = httplib.HTTPSConnection(firebase_url, firebase_port)
firebase_devel.request("GET", firbase_path)
firebase_devel_httpResponse = firebase_devel.getresponse()
result_firebase = firebase_devel_httpResponse.read()
result = json.loads(result_firebase)
print json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment