Skip to content

Commit c3c2ead

Browse files
committed
Fix clippy warnings
1 parent c34d7d8 commit c3c2ead

File tree

3 files changed

+48
-47
lines changed

3 files changed

+48
-47
lines changed

src/ac_scraper.rs

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub async fn add_task_name_to_problem_info(
6666
let body = acn
6767
.client
6868
.get(tasks_url.clone())
69-
.headers(acn.cookies.clone().unwrap_or(HeaderMap::new()))
69+
.headers(acn.cookies.clone().unwrap_or_default())
7070
.send()
7171
.await?
7272
.error_for_status()?
@@ -98,7 +98,7 @@ pub async fn add_task_name_to_problem_info(
9898
let now_idx = problem_id_to_index(&id)?;
9999
let config_idx = problem_id_to_index(config_id)?;
100100
if now_idx == config_idx {
101-
let task_screen_name: String = href.split('/').last().unwrap().to_string();
101+
let task_screen_name: String = href.split('/').next_back().unwrap().to_string();
102102
problem_info.task_screen_name = task_screen_name.clone();
103103
problem_str_info.insert("task_screen_name".to_string(), task_screen_name);
104104
return Ok((problem_info, problem_str_info));
@@ -116,7 +116,7 @@ async fn get_csrf_token(acn: &ACN, url: &str) -> Result<String> {
116116
let login_body = acn
117117
.client
118118
.get(url)
119-
.headers(acn.cookies.clone().unwrap_or(HeaderMap::new()))
119+
.headers(acn.cookies.clone().unwrap_or_default())
120120
.send()
121121
.await?
122122
.error_for_status()?
@@ -184,7 +184,7 @@ pub async fn ac_login(acn: &ACN) -> Result<()> {
184184
let resp = acn
185185
.client
186186
.post(LOGIN_URL)
187-
.headers(acn.cookies.clone().unwrap_or(HeaderMap::new()))
187+
.headers(acn.cookies.clone().unwrap_or_default())
188188
.form(&params)
189189
.send()
190190
.await?;
@@ -352,7 +352,7 @@ pub async fn ac_submit(
352352

353353
let submit_file = str_format(config_str_map["source_file_path"].clone(), &data_map);
354354
println!("{}{}", "Submit file: ".green(), submit_file);
355-
let source = fs::read(&full(&submit_file).unwrap().to_string())
355+
let source = fs::read(full(&submit_file).unwrap().to_string())
356356
.with_context(|| format!("Failed to read {}", submit_file))?;
357357
let source_str = String::from_utf8_lossy(&source);
358358

@@ -381,7 +381,7 @@ pub async fn ac_submit(
381381
let resp = acn
382382
.client
383383
.post(submit_url.as_str())
384-
.headers(acn.cookies.clone().unwrap_or(HeaderMap::new()))
384+
.headers(acn.cookies.clone().unwrap_or_default())
385385
.form(&params)
386386
.send()
387387
.await?;
@@ -426,12 +426,13 @@ pub async fn ac_submit(
426426
let mut finish = false;
427427
let mut finish_msg = String::from("");
428428
let mut timeout_cnt = 0;
429+
let status_re = Regex::new(r"^(\d+) */ *(\d+) *(.*)$").unwrap();
429430
while !finish {
430431
let submissions_url = str_format(SUBMISSIONS_URL.to_string(), &data_map);
431432
let req = acn
432433
.client
433434
.get(submissions_url)
434-
.headers(acn.cookies.clone().unwrap_or(HeaderMap::new()))
435+
.headers(acn.cookies.clone().unwrap_or_default())
435436
.timeout(tokio::time::Duration::from_millis(2000));
436437
let resp = req.send().await;
437438

@@ -464,24 +465,17 @@ pub async fn ac_submit(
464465

465466
let doc = Html::parse_document(&body.unwrap());
466467

467-
finish_msg = if submission_id.is_none() {
468-
let tr_selector = Selector::parse("table tbody tr").unwrap();
469-
let latest_row = doc.select(&tr_selector).next().unwrap();
470-
let submission = get_submission_info_from_row(&latest_row)?;
471-
submission_id = Some(submission.id.parse::<u64>().unwrap());
468+
finish_msg = if let Some(submission_id_value) = submission_id {
469+
let td_selector =
470+
Selector::parse(format!("td[data-id=\"{}\"]", submission_id_value).as_str())
471+
.unwrap();
472+
let target_row =
473+
ElementRef::wrap(doc.select(&td_selector).next().unwrap().parent().unwrap())
474+
.unwrap();
475+
let submission = get_submission_info_from_row(&target_row)?;
472476
let status = Status::from_table_str(&submission.status_str);
473-
if status != Status::WJ {
474-
let style = match status {
475-
Status::AC => bar_green_style.clone(),
476-
Status::WA => bar_red_style.clone(),
477-
_ => bar_yellow_style.clone(),
478-
};
479-
pb.set_style(style);
480-
pb.tick();
481-
}
482477
if status.as_str() != submission.status_str {
483-
let re = Regex::new(r"^(\d+) */ *(\d+) *(.*)$").unwrap();
484-
if let Some(caps) = re.captures(&submission.status_str) {
478+
if let Some(caps) = status_re.captures(&submission.status_str) {
485479
done = caps.get(1).unwrap().as_str().parse::<u64>().unwrap();
486480
all = caps.get(2).unwrap().as_str().parse::<u64>().unwrap();
487481
pb.set_length(all);
@@ -490,6 +484,15 @@ pub async fn ac_submit(
490484
} else if status != Status::WJ {
491485
finish = true;
492486
}
487+
if status != Status::WJ {
488+
let style = match status {
489+
Status::AC => bar_green_style.clone(),
490+
Status::WA => bar_red_style.clone(),
491+
_ => bar_yellow_style.clone(),
492+
};
493+
pb.set_style(style);
494+
pb.tick();
495+
}
493496
let msg = format!(
494497
"{} [ {} ]\n",
495498
make_submission_display(&submission),
@@ -499,25 +502,11 @@ pub async fn ac_submit(
499502
pb.set_message(msg.clone());
500503
msg
501504
} else {
502-
let td_selector =
503-
Selector::parse(format!("td[data-id=\"{}\"]", submission_id.unwrap()).as_str())
504-
.unwrap();
505-
let target_row =
506-
ElementRef::wrap(doc.select(&td_selector).next().unwrap().parent().unwrap())
507-
.unwrap();
508-
let submission = get_submission_info_from_row(&target_row)?;
505+
let tr_selector = Selector::parse("table tbody tr").unwrap();
506+
let latest_row = doc.select(&tr_selector).next().unwrap();
507+
let submission = get_submission_info_from_row(&latest_row)?;
508+
submission_id = Some(submission.id.parse::<u64>().unwrap());
509509
let status = Status::from_table_str(&submission.status_str);
510-
if status.as_str() != submission.status_str {
511-
let re = Regex::new(r"^(\d+) */ *(\d+) *(.*)$").unwrap();
512-
if let Some(caps) = re.captures(&submission.status_str) {
513-
done = caps.get(1).unwrap().as_str().parse::<u64>().unwrap();
514-
all = caps.get(2).unwrap().as_str().parse::<u64>().unwrap();
515-
pb.set_length(all);
516-
pb.set_position(done);
517-
}
518-
} else if status != Status::WJ {
519-
finish = true;
520-
}
521510
if status != Status::WJ {
522511
let style = match status {
523512
Status::AC => bar_green_style.clone(),
@@ -527,6 +516,16 @@ pub async fn ac_submit(
527516
pb.set_style(style);
528517
pb.tick();
529518
}
519+
if status.as_str() != submission.status_str {
520+
if let Some(caps) = status_re.captures(&submission.status_str) {
521+
done = caps.get(1).unwrap().as_str().parse::<u64>().unwrap();
522+
all = caps.get(2).unwrap().as_str().parse::<u64>().unwrap();
523+
pb.set_length(all);
524+
pb.set_position(done);
525+
}
526+
} else if status != Status::WJ {
527+
finish = true;
528+
}
530529
let msg = format!(
531530
"{} [ {} ]\n",
532531
make_submission_display(&submission),
@@ -556,7 +555,7 @@ pub async fn get_sample_cases(
556555
let body = acn
557556
.client
558557
.get(problem_url)
559-
.headers(acn.cookies.clone().unwrap_or(HeaderMap::new()))
558+
.headers(acn.cookies.clone().unwrap_or_default())
560559
.send()
561560
.await?
562561
.error_for_status()?
@@ -604,8 +603,7 @@ pub async fn get_sample_cases(
604603
outputs.push((index, pre_content.into()));
605604
}
606605
}
607-
if sample_case_id_arg.is_some() {
608-
let target = sample_case_id_arg.unwrap();
606+
if let Some(target) = sample_case_id_arg {
609607
inputs.retain(|x| x.0 == target);
610608
outputs.retain(|x| x.0 == target);
611609
}

src/check_samples.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ pub struct FailedDetail {
7575
pub index: usize,
7676
pub input: String,
7777
pub expected: String,
78+
#[allow(dead_code)]
7879
pub status: Status,
7980
pub output: String,
8081
}
8182

8283
pub struct SampleResults {
84+
#[allow(dead_code)]
8385
pub size: usize,
8486
pub total_status: Status,
8587
pub failed_details: Vec<FailedDetail>,

src/config.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ fn toml_into_config_vector(arr: Vec<toml::Value>, mut config_vector: ConfigVecto
218218
}
219219

220220
#[derive(Debug, Serialize, Deserialize, Clone)]
221+
#[allow(dead_code)]
221222
pub struct Config {
222223
pub work_space: Option<String>,
223224
pub abc_dir_name: Option<String>,
@@ -304,10 +305,10 @@ pub async fn get_problem_info_from_path(
304305
}
305306
}
306307

307-
if contest_type.is_some() && contest_id.is_some() {
308+
if let (Some(contest_type), Some(contest_id)) = (contest_type.as_deref(), contest_id) {
308309
let problem_info = ProblemInfo {
309-
contest_type: ContestType::from_str(contest_type.unwrap().as_str()).unwrap(),
310-
contest_id: contest_id.unwrap(),
310+
contest_type: ContestType::from_str(contest_type).unwrap(),
311+
contest_id,
311312
problem_id,
312313
task_screen_name: "".into(),
313314
};

0 commit comments

Comments
 (0)