Skip to content

Commit

Permalink
Handle EU consent popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubbler-4 committed Aug 5, 2024
1 parent 1e5a731 commit f31af90
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 deletions.
38 changes: 23 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gaboja"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
license = "MIT"
description = "Gaboja: CLI helper for solving BOJ problems"
Expand All @@ -23,6 +23,6 @@ regex = "1.10.4"
serde = "1.0.203"
serde_json = "1.0.117"
similar = { version = "2.5.0", features = ["inline"] }
thirtyfour = "0.32.0"
thirtyfour = "0.33.0"
tokio = { version = "1.37.0", features = ["time", "process", "rt"] }
toml = "0.8.13"
3 changes: 3 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ pub(crate) enum Command {
Help,
Exit,
Shell(String),
DebugCache,
DebugScreenshot,
DebugSource,
}

#[derive(Debug, Clone)]
Expand Down
10 changes: 10 additions & 0 deletions src/command/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ impl GlobalState {
Command::Shell(shell_cmd) => {
run_interactive(shell_cmd)?;
}
Command::DebugCache => {
println!("{:?}", self.problem_cache);
}
Command::DebugScreenshot => {
self.browser.screenshot()?;
}
Command::DebugSource => {
let source = self.browser.source()?;
std::fs::write("./source", &source)?;
}
}
Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions src/command/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ impl std::str::FromStr for Command {
Ok(Self::Exit)
}
"help" => Ok(Self::Help),
"debugcache" => Ok(Self::DebugCache),
"debugscreenshot" => Ok(Self::DebugScreenshot),
"debugsource" => Ok(Self::DebugSource),
_ => Err(CommandParseError {
msg: format!("Unknown command `{}`", main_cmd),
}),
Expand Down
21 changes: 21 additions & 0 deletions src/infra/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::data::{ExampleIO, Problem, ProblemId, ProblemKind};
use crate::infra::console::Spinner;
use crate::infra::subprocess::{spawn_cmd_background, run_silent};
use std::future::Future;
use std::path::Path;
use std::process::Stdio;
use thirtyfour::common::cookie::SameSite;
use thirtyfour::prelude::*;
Expand Down Expand Up @@ -103,6 +104,10 @@ impl Browser {
let driver = &self.webdriver;
let problem_page = problem_id.problem_url();
driver.get(problem_page).await?;
let fc_cta_consent = driver.find_all(By::ClassName("fc-cta-consent")).await?;
if let Some(cta_el) = fc_cta_consent.first() {
cta_el.click().await?;
}
let title = driver.find(By::Id("problem_title")).await?.text().await?;
let label_elems = driver.find_all(By::ClassName("problem-label")).await?;
let mut kind = vec![];
Expand Down Expand Up @@ -216,6 +221,22 @@ impl Browser {
})
}

pub(crate) fn screenshot(&self) -> anyhow::Result<()> {
with_async_runtime(async {
let driver = &self.webdriver;
driver.screenshot(Path::new("./screenshot.png")).await?;
Ok(())
})
}

pub(crate) fn source(&self) -> anyhow::Result<String> {
with_async_runtime(async {
let driver = &self.webdriver;
let source = driver.source().await?;
Ok(source)
})
}

/// Gracefully terminate the browser. Should be called even on error.
pub(crate) fn quit(self) -> anyhow::Result<()> {
with_async_runtime(async {
Expand Down

0 comments on commit f31af90

Please sign in to comment.