forked from marecotec/Home_Assistant_Oil_Smart_Oil_Gauge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oil_multiple.py
49 lines (41 loc) · 2.32 KB
/
oil_multiple.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
38
39
40
41
42
43
44
45
46
47
48
49
from selenium import webdriver
import paho.mqtt.publish as publish
import json
from pyvirtualdisplay import Display
from webdriver_manager.chrome import ChromeDriverManager
display = Display(visible=0, size=(1440, 1024))
display.start()
options = webdriver.ChromeOptions()
options.add_argument('--headless')
browser = webdriver.Chrome(ChromeDriverManager().install(),options=options)
browser.set_window_size(1440, 1024)
user_name = "YOUR_SMART_OIL_USERNAME"
password = "YOUR_SMART_OIL_PASSWORD"
mqtt_server = "YOUR_MQTT_SERVER"
mqtt_user = "YOUR_MQTT_USER"
mqtt_password = "YOUR_MQTT_PASSWORD"
browser.get("https://app.smartoilgauge.com/app.php")
browser.find_element_by_id("inputUsername").send_keys(user_name)
browser.find_element_by_id("inputPassword").send_keys(password)
browser.find_element_by_css_selector("button.btn").click()
browser.implicitly_wait(3)
var = browser.find_element_by_xpath('//p[contains(text(), "/")]').text
fill_level = browser.find_element_by_xpath("//div[@class='ts_col ts_level']//div[@class='ts_col_val']//p").get_attribute("innerHTML")
fill_level = fill_level.split(r"/")
current_fill_level = fill_level[0]
current_fill_proportion = round((float(str(fill_level[0])) / float(str(fill_level[1]))) * 100, 1)
battery_status = browser.find_element_by_xpath("//div[@class='ts_col ts_battery']//div[@class='ts_col_val']//p").get_attribute("innerHTML")
days_to_low = browser.find_element_by_xpath("//div[@class='ts_col ts_days_to_low']//div[@class='ts_col_val']//p").get_attribute("innerHTML")
max_fill = browser.find_element_by_xpath("//*[@id='tankSummary']/div[1]/div[4]/div[2]/p").get_attribute("innerHTML")
print(current_fill_level)
print(current_fill_proportion)
print(battery_status)
print(days_to_low)
print(max_fill)
msgs = [{"topic": "oilgauge/tanklevel", "payload": json.dumps({"current_fill_level": current_fill_level,
"current_fill_proportion": current_fill_proportion,
"max_fill": max_fill,
"battery_status": battery_status,
"days_to_low": days_to_low }) }]
browser.quit()
publish.multiple(msgs, hostname=mqtt_server, port=1883, auth={'username':mqtt_user, 'password':mqtt_password})