Last active
July 13, 2016 12:56
-
-
Save chaeplin/7429af33aff4d922aa969b47ae8ee988 to your computer and use it in GitHub Desktop.
nest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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