summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs7
-rw-r--r--src/web.rs11
2 files changed, 10 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 941b299..84ae088 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,7 +10,7 @@
#![recursion_limit = "128"]
#![allow(clippy::cast_precision_loss)]
-use thirtyfour::error::WebDriverResult;
+use {port_scanner::request_open_port, thirtyfour::error::WebDriverResult};
mod schedule;
mod web;
@@ -24,6 +24,7 @@ struct Cache {
#[tokio::main]
async fn main() -> WebDriverResult<()> {
+ let port = request_open_port().unwrap_or(9515);
let cache = format!("{}/rin_cache", std::env::temp_dir().display());
if std::path::Path::new(&cache).exists()
@@ -53,8 +54,8 @@ async fn main() -> WebDriverResult<()> {
}
let mut geckodriver =
- web::geckodriver().expect("failed to start geckodriver");
- let driver = web::webdriver().await.expect("failed to start webdriver");
+ web::geckodriver(port).expect("failed to start geckodriver");
+ let driver = web::webdriver(port).await.expect("failed to start webdriver");
let markdown =
schedule::to_markdown(&driver).await.expect("failed to get schedule");
let schedule = schedule::markdown_to_map(&markdown);
diff --git a/src/web.rs b/src/web.rs
index eb10ff2..1fa8a27 100644
--- a/src/web.rs
+++ b/src/web.rs
@@ -1,20 +1,21 @@
use {thirtyfour::WebDriver, tokio::process::Command};
-pub fn geckodriver() -> Result<tokio::process::Child, std::io::Error> {
+pub fn geckodriver(port: u16) -> Result<tokio::process::Child, std::io::Error> {
Command::new("geckodriver")
- .arg("--port=9515")
+ .arg(format!("--port={port}"))
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.spawn()
}
-pub async fn webdriver() -> Result<WebDriver, thirtyfour::error::WebDriverError>
-{
+pub async fn webdriver(
+ port: u16,
+) -> Result<WebDriver, thirtyfour::error::WebDriverError> {
let mut caps = thirtyfour::DesiredCapabilities::firefox();
caps.set_headless().expect("failed to set headless");
- let driver = WebDriver::new("http://localhost:9515", caps)
+ let driver = WebDriver::new(&format!("http://localhost:{port}"), caps)
.await
.expect("failed to connect to webdriver");