Skip to content

Commit 1931b11

Browse files
committed
refactoring
1 parent 4b9f006 commit 1931b11

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

atcoder-problems-backend/src/bin/crawl_all_submissions.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@ async fn main() {
2424
match load_contest(&url).await {
2525
Ok(contests) => {
2626
for contest in contests {
27-
match AtCoderClient::new(&username, &password).await {
28-
Ok(client) => {
29-
finish_one_contest(&url, &contest.id, client).await;
30-
}
31-
Err(e) => {
32-
error!("Failed to login to AtCoder: {:?}", e);
33-
}
34-
}
27+
finish_one_contest(&url, &contest.id, &username, &password).await;
3528
}
3629
}
3730
Err(e) => {
@@ -42,10 +35,10 @@ async fn main() {
4235
}
4336
}
4437

45-
async fn finish_one_contest(url: &str, contest_id: &str, client: AtCoderClient) {
38+
async fn finish_one_contest(url: &str, contest_id: &str, username: &str, password: &str) {
4639
loop {
4740
info!("Starting {}", contest_id);
48-
match crawl_one_contest(url, contest_id, client.clone()).await {
41+
match crawl_one_contest(url, contest_id, username, password).await {
4942
Ok(_) => {
5043
info!("Finished {}", contest_id);
5144
return;
@@ -58,8 +51,14 @@ async fn finish_one_contest(url: &str, contest_id: &str, client: AtCoderClient)
5851
}
5952
}
6053

61-
async fn crawl_one_contest(url: &str, contest_id: &str, client: AtCoderClient) -> Result<()> {
54+
async fn crawl_one_contest(
55+
url: &str,
56+
contest_id: &str,
57+
username: &str,
58+
password: &str,
59+
) -> Result<()> {
6260
let db = initialize_pool(url).await?;
61+
let client = AtCoderClient::new(username, password).await?;
6362
let crawler = WholeContestCrawler::new(db, client.clone(), contest_id);
6463
crawler.crawl().await?;
6564
Ok(())

0 commit comments

Comments
 (0)