80 lines
1.8 KiB
Python
80 lines
1.8 KiB
Python
import os.path
|
|
import time
|
|
import pprint
|
|
|
|
from wci import wci
|
|
from credentials import user, password
|
|
import json
|
|
from folder_mgr.folder_mgr import get_date, date_has_changed, FolderMgr
|
|
|
|
INTERVAL = 60
|
|
|
|
# Values after training
|
|
# Convert and write JSON object to file
|
|
|
|
|
|
def main():
|
|
w = wci.WeConnectId(user, password)
|
|
|
|
vehicles = w.get('/vehicles')
|
|
print('list of vehicles:')
|
|
for key in vehicles:
|
|
print(key)
|
|
|
|
vin = vehicles['data'][0]['vin']
|
|
|
|
pprint.pprint(vehicles)
|
|
domains = [
|
|
"access",
|
|
"charging",
|
|
"climatisation",
|
|
"climatisationTimers",
|
|
"fuelStatus",
|
|
"userCapabilities",
|
|
"vehicleLights",
|
|
"vehicleHealthInspection",
|
|
"oilLevel",
|
|
"measurements"
|
|
]
|
|
endpoint = '/vehicles/' + vin + '/selectivestatus?jobs='
|
|
for domain in domains:
|
|
endpoint += domain + ','
|
|
endpoint = endpoint[:-1]
|
|
# endpoint = '/vehicles/' + vehicles['data'][0]['vin'] + f'/selectivestatus?jobs=access,charging,climatisation,climatisationTimers,fuelStatus,userCapabilities,vehicleLights,vehicleHealthInspection,oilLevel,measurements'
|
|
print(f'Endpoint: {endpoint}')
|
|
|
|
data_list = []
|
|
_date_last = {}
|
|
f_mgr = FolderMgr()
|
|
|
|
while True:
|
|
start = time.time()
|
|
_date = get_date()
|
|
if date_has_changed(_date_last, _date):
|
|
data_list = []
|
|
|
|
try:
|
|
data = w.get(endpoint)
|
|
print(data)
|
|
data_list.append(data)
|
|
folder = f_mgr.update(f"results/{vin}", _date)
|
|
time_str = f"{_date['hour']}-{_date['min']}-{_date['sec']}"
|
|
date_str = f"{_date['year']}-{_date['month']}-{_date['day']}"
|
|
filename = f"vehicle_data_{date_str}_{time_str}.json"
|
|
_path = os.path.join(folder, filename)
|
|
with open(_path, "w") as fp:
|
|
json.dump(data_list, fp, indent=4)
|
|
|
|
except Exception:
|
|
pass
|
|
|
|
stop = time.time()
|
|
diff = stop - start
|
|
time.sleep(max(0, INTERVAL - diff))
|
|
_date_last = _date
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|