2020-10-09 16:31:21 +02:00
|
|
|
use color_eyre::Result;
|
2020-10-09 13:30:37 +02:00
|
|
|
use std::thread;
|
|
|
|
use std::time::{Duration, SystemTime};
|
2020-10-09 16:31:21 +02:00
|
|
|
use thirtyfour_sync::prelude::*;
|
2020-10-09 13:30:37 +02:00
|
|
|
|
|
|
|
const USERNAME: &'static str = "pja@vtilburg.net";
|
|
|
|
const PASSWORD: &'static str = "XXXXXXXXXXXXXXXX";
|
|
|
|
const URL: &'static str = "https://my.autarco.com/";
|
|
|
|
|
2020-10-09 16:31:21 +02:00
|
|
|
const GECKO_DRIVER_PORT: u16 = 18019;
|
2020-10-09 13:30:37 +02:00
|
|
|
|
2020-10-09 16:31:21 +02:00
|
|
|
use std::process::{Child, Command, Stdio};
|
|
|
|
|
|
|
|
struct GeckoDriver(Child);
|
|
|
|
|
|
|
|
impl GeckoDriver {
|
|
|
|
pub fn spawn() -> Result<Self> {
|
|
|
|
// This is taken from the webdriver-client crate.
|
|
|
|
let child = Command::new("geckodriver")
|
|
|
|
.arg("-b")
|
|
|
|
.arg("firefox")
|
|
|
|
.arg("--port")
|
|
|
|
.arg(format!("{}", GECKO_DRIVER_PORT))
|
|
|
|
.stdin(Stdio::null())
|
|
|
|
.stderr(Stdio::null())
|
|
|
|
.stdout(Stdio::null())
|
|
|
|
.spawn()?;
|
|
|
|
thread::sleep(Duration::new(1, 500));
|
|
|
|
|
|
|
|
Ok(GeckoDriver(child))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for GeckoDriver {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
let _ = self.0.kill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
color_eyre::install()?;
|
|
|
|
|
|
|
|
let _gecko_driver = GeckoDriver::spawn()?;
|
|
|
|
let mut caps = DesiredCapabilities::firefox();
|
|
|
|
caps.set_headless()?;
|
|
|
|
let driver = WebDriver::new(&format!("http://localhost:{}", GECKO_DRIVER_PORT), &caps)?;
|
|
|
|
|
|
|
|
// Got to the My Autarco site
|
|
|
|
driver.get(URL)?;
|
2020-10-09 13:30:37 +02:00
|
|
|
|
|
|
|
// Log in
|
2020-10-09 16:31:21 +02:00
|
|
|
let input = driver.find_element(By::Id("username"))?;
|
2020-10-09 13:30:37 +02:00
|
|
|
input.send_keys(USERNAME)?;
|
2020-10-09 16:31:21 +02:00
|
|
|
let input = driver.find_element(By::Id("password"))?;
|
2020-10-09 13:30:37 +02:00
|
|
|
input.send_keys(PASSWORD)?;
|
2020-10-09 16:31:21 +02:00
|
|
|
let input = driver.find_element(By::Css("button[type=submit]"))?;
|
2020-10-09 13:30:37 +02:00
|
|
|
input.click()?;
|
|
|
|
|
|
|
|
loop {
|
|
|
|
thread::sleep(Duration::from_secs(60));
|
|
|
|
|
|
|
|
// let screenshot = session.screenshot()?;
|
|
|
|
// screenshot.save_file("screenshot.png")?;
|
|
|
|
|
|
|
|
// Retrieve the data from the elements
|
|
|
|
let time = SystemTime::now()
|
|
|
|
.duration_since(SystemTime::UNIX_EPOCH)
|
|
|
|
.unwrap()
|
|
|
|
.as_secs();
|
|
|
|
println!("time: {}", time);
|
|
|
|
|
2020-10-09 16:31:21 +02:00
|
|
|
let current = driver.find_element(By::Css("h2#pv-now b"))?;
|
2020-10-09 13:30:37 +02:00
|
|
|
println!("current: {} W", current.text()?);
|
|
|
|
|
2020-10-09 16:31:21 +02:00
|
|
|
let total = driver.find_element(By::Css("h2#pv-to-date b"))?;
|
2020-10-09 13:30:37 +02:00
|
|
|
println!("total: {} kWh", total.text()?);
|
|
|
|
|
|
|
|
println!();
|
|
|
|
}
|
|
|
|
}
|