diff --git a/src/cgg_data_source.rs b/src/cgg_data_source.rs index de311ac..09ec713 100644 --- a/src/cgg_data_source.rs +++ b/src/cgg_data_source.rs @@ -91,8 +91,7 @@ impl CGGDataSource { fn extract_json(pattern: &str, page: &str) -> String { let json = page[page.find(pattern).unwrap() + pattern.len()..].to_owned(); - json[..json.find("};").unwrap() + 1] - .replace("undefined", "null") + json[..json.find("};").unwrap() + 1].replace("undefined", "null") } impl DataSource for CGGDataSource { diff --git a/src/kb_data_source.rs b/src/kb_data_source.rs index f54bf0e..3e161ee 100644 --- a/src/kb_data_source.rs +++ b/src/kb_data_source.rs @@ -101,7 +101,7 @@ impl KBDataSource { } // It will be better to use Result... - fn get_auth_token(&self, client: &ureq::Agent) -> Option { + fn get_auth_token(&self, client: &ureq::Agent) -> Option { let mut bundle = match client.get("https://koreanbuilds.net/bundle.js").call() { Ok(resp) => match resp.into_string() { Ok(val) => val, @@ -123,7 +123,7 @@ impl KBDataSource { Some(position) => Some((&bundle[..position]).to_string()), None => None, } - } + } fn get_classname_mapping(&self, client: &ureq::Agent) -> IndexMap { let mut mapping = IndexMap::new(); @@ -241,9 +241,7 @@ impl DataSource for KBDataSource { } }; let mut blocks = vec![]; - let mut winrate = 0.0; if !data.builds2.is_empty() { - winrate = (data.builds2[0].wins / data.builds2[0].games) * 100.; let mut starting_items: Vec = vec![]; if data.builds2[0].start_item0.item_id != 0 { starting_items.push(Item { @@ -338,15 +336,16 @@ impl DataSource for KBDataSource { ), items: final_items })); + return Some(( + blocks, + Stat { + win_rate: (data.builds2[0].wins / data.builds2[0].games) * 100., + games: data.builds2[0].games as u32, + kda: 0.0, + }, + )); } - Some(( - blocks, - Stat { - win_rate: winrate, - games: data.builds2[0].games as u32, - kda: 0.0, - }, - )) + None } }