Skip to content

Commit

Permalink
Fixes for new format of codeforces status
Browse files Browse the repository at this point in the history
Fixes for luogo
  • Loading branch information
EgorKulikov committed Dec 9, 2024
1 parent d0c8a78 commit 69aa57d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
64 changes: 46 additions & 18 deletions src/codeforces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,21 @@ pub async fn submit(
Some(pos) => pos,
};
let id = url[pos + 9..].replace("/", "");
let submit_url = if url.contains("problemset") {
"https://mirror.codeforces.com/problemset/submit".to_string()
let (submit_url, status_url) = if url.contains("problemset") {
let slash = url[pos + 9..].find('/').unwrap();
(
"https://mirror.codeforces.com/problemset/submit".to_string(),
format!(
"https://codeforces.com/problemset/submission/{}/",
&url[pos + 9..pos + 9 + slash]
),
)
} else {
url[..pos].replace("https://codeforces.com", "https://mirror.codeforces.com") + "/submit"
(
url[..pos].replace("https://codeforces.com", "https://mirror.codeforces.com")
+ "/submit",
format!("{}/submission/", &url[..pos]),
)
};
driver.goto(&submit_url).await?;
skip_cloudflare(driver).await?;
Expand Down Expand Up @@ -130,7 +141,22 @@ pub async fn submit(
return Ok(());
}
let mut last_verdict = "".to_string();
let mut printed_url = false;
loop {
clear(last_verdict.len());
if !printed_url {
if let Ok(id_cell) = driver.find(By::ClassName("id-cell")).await {
if let Some(id) = id_cell
.find(By::Tag("a"))
.await?
.attr("submissionid")
.await?
{
printed_url = true;
println!("Submission url {}{}", status_url, id);
}
}
}
match iteration(driver, &mut last_verdict).await {
Ok(res) => {
if res {
Expand All @@ -146,22 +172,25 @@ pub async fn submit(
},
}
}
let id_cell = driver.find(By::ClassName("id-cell")).await?;
if let Some(link) = id_cell.find(By::Tag("a")).await?.attr("href").await? {
println!("Submission url https://codeforces.com{}", link);
}
Ok(())
}

async fn iteration(driver: &WebDriver, last_verdict: &mut String) -> WebDriverResult<bool> {
driver.screenshot(&Path::new("screenshot.png")).await?;
save_source(driver).await?;
let mut stdout = std::io::stdout();
let cell = driver.find(By::ClassName("status-cell")).await?;
let verdict = cell.text().await?;
let (is_waiting, is_accepted) = match cell.find(By::Tag("span")).await {
Ok(verdict) => (
verdict.class_name().await? == Some("verdict-waiting".to_string()),
verdict.class_name().await? == Some("verdict-accepted".to_string()),
),
Ok(mut verdict) => {
if verdict.class_name().await? == Some("submissionVerdictWrapper".to_string()) {
verdict = verdict.find(By::Tag("span")).await?;
}
(
verdict.class_name().await? == Some("verdict-waiting".to_string()),
verdict.class_name().await? == Some("verdict-accepted".to_string()),
)
}
Err(_) => {
if verdict.trim() == "Compilation error" {
(false, false)
Expand All @@ -170,13 +199,6 @@ async fn iteration(driver: &WebDriver, last_verdict: &mut String) -> WebDriverRe
}
}
};
clear(last_verdict.len());
if verdict == *last_verdict && is_waiting {
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
driver.refresh().await?;
skip_cloudflare(driver).await?;
return Ok(false);
}
let _ = execute!(
stdout,
SetForegroundColor(if is_waiting {
Expand All @@ -189,6 +211,12 @@ async fn iteration(driver: &WebDriver, last_verdict: &mut String) -> WebDriverRe
);
print!("{}", verdict);
let _ = execute!(stdout, ResetColor);
if verdict == *last_verdict && is_waiting {
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
driver.refresh().await?;
skip_cloudflare(driver).await?;
return Ok(false);
}
if !is_waiting {
println!();
return Ok(true);
Expand Down
6 changes: 3 additions & 3 deletions src/luogu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ async fn iteration(driver: &WebDriver, last_verdict: &mut String) -> WebDriverRe
let mut global_verdict = None;
let mut points = None;
for i in 0..spans.len() {
if spans[i].text().await?.contains("评测状态") {
if spans[i].text().await?.contains("评测状态") && i + 2 < spans.len() {
global_verdict = Some(spans[i + 2].text().await?.trim().to_string());
}
if spans[i].text().await?.contains("评测分数") {
if spans[i].text().await?.contains("评测分数") && i + 3 < spans.len() {
points = Some(spans[i + 3].text().await?.trim().to_string());
}
}
Expand Down Expand Up @@ -225,7 +225,7 @@ async fn iteration(driver: &WebDriver, last_verdict: &mut String) -> WebDriverRe
let _ = execute!(stdout, ResetColor);
if total != 0 && pending == 0 {
println!();
let mut id = 0;
let mut id = 1;
for (name, tests) in cards {
println!("{}", name);
for test in tests {
Expand Down

0 comments on commit 69aa57d

Please sign in to comment.