Apply fixed directory of chromedriver

This commit is contained in:
Sik Yoon 2023-07-16 01:14:05 +09:00
parent 0c4e8ada55
commit f7048b0c9a
2 changed files with 28 additions and 17 deletions

Binary file not shown.

View File

@ -11,11 +11,9 @@ use reqwest::{Client, ClientBuilder};
use rust_decimal::{prelude::FromPrimitive, prelude::ToPrimitive, Decimal, RoundingStrategy};
use rust_decimal_macros::dec;
use sqlx::FromRow;
use std::{io, io::Write, process::Stdio};
use std::{io, io::Write, process::Stdio, path::Path};
use tokio::{fs::*, io::ErrorKind, process::Command, task::JoinHandle, time::*};
const WEB_DRIVER_PATH: &str = "E:/[Cryptocurrency]/tradingbot/webdriver/chromedriver.exe";
const WEB_DRIVER_PATH2: &str = "C:/tradingbot_complete/webdriver/chromedriver.exe";
const STRATEGIST_NUMBER: u32 = 16;
pub async fn initialization() {
@ -83,23 +81,36 @@ async fn initialize_webdriver() {
io::stdout().flush();
let mut output;
output = Command::new(WEB_DRIVER_PATH)
let os_type = std::env::consts::OS;
let mut chrome_webdriver_path = std::path::PathBuf::new();
chrome_webdriver_path.push(std::env::current_dir().unwrap());
chrome_webdriver_path.push("chromedriver");
match os_type {
"linux" => {
chrome_webdriver_path.push("chromedriver");
},
"windows" => {
chrome_webdriver_path.push("chromedriver.exe");
},
_ => {
eprintln!("\ntradingbot supports only Linux and Windows.");
panic!();
}
}
if !chrome_webdriver_path.exists() {
eprintln!("\nCheck if there is chromedriver.exe ({})", chrome_webdriver_path.to_str().unwrap());
panic!();
}
output = Command::new(chrome_webdriver_path)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn();
output.expect("\nOpening chromedriver failed!");
if output.is_ok() {
output.unwrap();
} else {
output = Command::new(WEB_DRIVER_PATH2)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn();
output.unwrap();
}
println!("Ok");
}