working
This commit is contained in:
@@ -160,3 +160,5 @@ cython_debug/
|
|||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
results/
|
||||||
|
|||||||
+47
-12
@@ -1,9 +1,16 @@
|
|||||||
|
import os.path
|
||||||
import time
|
import time
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
from we_connect import wci
|
from wci import wci
|
||||||
from credentials import user, password
|
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():
|
def main():
|
||||||
@@ -14,30 +21,58 @@ def main():
|
|||||||
for key in vehicles:
|
for key in vehicles:
|
||||||
print(key)
|
print(key)
|
||||||
|
|
||||||
pprint.pprint(vehicles)
|
vin = vehicles['data'][0]['vin']
|
||||||
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 += ','
|
|
||||||
|
|
||||||
|
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'
|
# endpoint = '/vehicles/' + vehicles['data'][0]['vin'] + f'/selectivestatus?jobs=access,charging,climatisation,climatisationTimers,fuelStatus,userCapabilities,vehicleLights,vehicleHealthInspection,oilLevel,measurements'
|
||||||
print(f'Endpoint: {endpoint}')
|
print(f'Endpoint: {endpoint}')
|
||||||
|
|
||||||
|
data_list = []
|
||||||
|
_date_last = {}
|
||||||
|
f_mgr = FolderMgr()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
_date = get_date()
|
||||||
|
if date_has_changed(_date_last, _date):
|
||||||
|
data_list = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = w.get(endpoint)
|
data = w.get(endpoint)
|
||||||
print(data)
|
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:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
stop = time.time()
|
stop = time.time()
|
||||||
diff = stop - start
|
diff = stop - start
|
||||||
time.sleep(60-diff)
|
time.sleep(max(0, INTERVAL - diff))
|
||||||
|
_date_last = _date
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def get_date() -> dict:
|
||||||
|
_result = {}
|
||||||
|
now = time.gmtime()
|
||||||
|
_result["year"] = now.tm_year
|
||||||
|
_result["month"] = now.tm_mon
|
||||||
|
_result["day"] = now.tm_mday
|
||||||
|
_result["hour"] = now.tm_hour
|
||||||
|
_result["min"] = now.tm_min
|
||||||
|
_result["sec"] = now.tm_sec
|
||||||
|
|
||||||
|
return _result
|
||||||
|
|
||||||
|
|
||||||
|
def date_has_changed(d1: dict, d2: dict, fields=['year', 'month', 'day']):
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
for field in fields:
|
||||||
|
if d1[field] != d2[field]:
|
||||||
|
count += 1
|
||||||
|
except KeyError:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return count > 0
|
||||||
|
|
||||||
|
|
||||||
|
class FolderMgr:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def update(base_folder: str, _date: dict, fields=['year', 'month', 'day']) -> str:
|
||||||
|
|
||||||
|
appendix = ''
|
||||||
|
for field in fields:
|
||||||
|
appendix += f"{_date[field]}/"
|
||||||
|
|
||||||
|
folder = os.path.join(base_folder, appendix[:-1])
|
||||||
|
try:
|
||||||
|
os.makedirs(folder)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return folder
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
date = get_date()
|
||||||
|
print(date)
|
||||||
|
mgr = FolderMgr()
|
||||||
|
|
||||||
|
for i in range(0, 10):
|
||||||
|
folder = mgr.update("./", get_date(), fields=['year', 'month', 'day', 'hour', 'min', 'sec'])
|
||||||
|
print(folder)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user