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, to_date_str, to_time_str, FolderMgr INTERVAL = 5*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() _date_start = get_date() 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) filename = f"vehicle_{vin}_{to_date_str(_date_start)}_{to_time_str(_date_start)}.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()