daily pastebin goal
58%
SHARE
TWEET

Tesla Model S API Example

Teslaliving Dec 31st, 2015 1,666 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3.  
  4. import os
  5. import teslajson
  6.  
  7. TESLA_EMAIL = os.environ['TESLA_EMAIL']
  8. TESLA_PASSWORD = os.environ['TESLA_PASSWORD']
  9.  
  10. def establish_connection(token=None):
  11.     c = teslajson.Connection(email=TESLA_EMAIL, password=TESLA_PASSWORD, access_token=token)
  12.     return c
  13.    
  14. def get_odometer(c, car):
  15.     odometer = None
  16.     for v in c.vehicles:
  17.         if v["display_name"] == car:
  18.             d = v.data_request("vehicle_state")
  19.             odometer = int(d["odometer"])
  20.     return odometer
  21.    
  22. c = establish_connection()
  23. print get_odometer(c, "Baddog")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top