From 909e2cbdf8cbb311f4abef2c0c1d176987580a76 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Wed, 4 Aug 2021 17:22:21 +0200 Subject: feat: get faculties for the /room command --- src/browser/web_browser.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/browser/web_browser.rs') diff --git a/src/browser/web_browser.rs b/src/browser/web_browser.rs index 804c82f..d2ba6c4 100644 --- a/src/browser/web_browser.rs +++ b/src/browser/web_browser.rs @@ -1,10 +1,13 @@ use crate::Config; +use std::collections::HashMap; use std::{thread, time}; +use thirtyfour::common::capabilities::firefox::FirefoxPreferences; use thirtyfour::error::{WebDriverError, WebDriverErrorInfo, WebDriverErrorValue}; use thirtyfour::prelude::{By, WebDriverResult}; use thirtyfour::{FirefoxCapabilities, WebDriver, WebDriverCommands}; const LOGIN_URL: &str = "https://studenti.smartedu.unict.it/WorkFlow2011/Logon/Logon.aspx?ReturnUrl=%2fStudenti%2fDefault.aspx"; +const ROOMS_URL: &str = "https://studenti.smartedu.unict.it/StudentSpaceReserv?Type=unaTantum"; pub struct Browser { driver: Option, @@ -70,6 +73,37 @@ impl Browser { Ok(()) } + + pub async fn faculties(&self) -> WebDriverResult>> { + if let Some(_d) = &self.driver { + _d.get(ROOMS_URL).await?; + thread::sleep(time::Duration::from_millis(1000)); + + _d.find_element(By::Css( + "span[aria-labelledby='select2-dipartimentoSelector-container']", + )) + .await? + .click() + .await?; + + let list_elements = _d + .find_elements(By::Css("#select2-dipartimentoSelector-results li")) + .await?; + + let mut faculties_ids = HashMap::::new(); + + for i in list_elements { + faculties_ids.insert( + i.get_attribute("data-select2-id").await.unwrap().unwrap(), + i.text().await.unwrap(), + ); + } + + return Ok(Some(faculties_ids)); + } + + Ok(None) + } } pub static mut WEB_BROWSER: Option = None; -- cgit v1.2.3-18-g5258