-
Notifications
You must be signed in to change notification settings - Fork 0
/
getcar.py
37 lines (27 loc) · 929 Bytes
/
getcar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
# prints out json config for cars in your tesla account
import json
import teslapy
# load json config file
def get_config(key):
with open('config.json', 'r') as file:
data = json.load(file)
file.close()
return data[key]
# get car status data
def get_data(self):
return self.get_vehicle_data()
# main routine
def main():
# instantiate tesla object
tesla = teslapy.Tesla(get_config("account"))
if not tesla.authorized:
print('Use browser to login. Page Not Found will be shown at success.')
print('Open this URL: ' + tesla.authorization_url())
tesla.fetch_token(authorization_response=input('Enter URL after authentication: '))
# loop through vehicles
for vehicle in tesla.vehicle_list():
car_state = get_data(vehicle)
print(car_state)
if __name__ == "__main__":
main()