working
This commit is contained in:
+47
-12
@@ -1,9 +1,16 @@
|
||||
import os.path
|
||||
import time
|
||||
import pprint
|
||||
|
||||
from we_connect import wci
|
||||
from wci import wci
|
||||
from credentials import user, password
|
||||
from we_connect.domains import Domain
|
||||
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():
|
||||
@@ -14,30 +21,58 @@ def main():
|
||||
for key in vehicles:
|
||||
print(key)
|
||||
|
||||
pprint.pprint(vehicles)
|
||||
domains = [Domain.ALL_CAPABLE]
|
||||
endpoint = '/vehicles/' + vehicles['data'][0]['vin'] + '/selectivestatus?jobs='
|
||||
count = len(domains)
|
||||
for domain in domains:
|
||||
endpoint += domain.value
|
||||
count -= 1
|
||||
if count > 0:
|
||||
endpoint += ','
|
||||
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(60-diff)
|
||||
time.sleep(max(0, INTERVAL - diff))
|
||||
_date_last = _date
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user