Fix panic
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nyyu 2021-03-14 18:10:51 +01:00
parent dd5faf3e96
commit 3f7de3abac
2 changed files with 12 additions and 14 deletions

View file

@ -91,8 +91,7 @@ impl CGGDataSource {
fn extract_json(pattern: &str, page: &str) -> String { fn extract_json(pattern: &str, page: &str) -> String {
let json = page[page.find(pattern).unwrap() + pattern.len()..].to_owned(); let json = page[page.find(pattern).unwrap() + pattern.len()..].to_owned();
json[..json.find("};").unwrap() + 1] json[..json.find("};").unwrap() + 1].replace("undefined", "null")
.replace("undefined", "null")
} }
impl DataSource for CGGDataSource { impl DataSource for CGGDataSource {

View file

@ -101,7 +101,7 @@ impl KBDataSource {
} }
// It will be better to use Result... // It will be better to use Result...
fn get_auth_token(&self, client: &ureq::Agent) -> Option<String> { fn get_auth_token(&self, client: &ureq::Agent) -> Option<String> {
let mut bundle = match client.get("https://koreanbuilds.net/bundle.js").call() { let mut bundle = match client.get("https://koreanbuilds.net/bundle.js").call() {
Ok(resp) => match resp.into_string() { Ok(resp) => match resp.into_string() {
Ok(val) => val, Ok(val) => val,
@ -123,7 +123,7 @@ impl KBDataSource {
Some(position) => Some((&bundle[..position]).to_string()), Some(position) => Some((&bundle[..position]).to_string()),
None => None, None => None,
} }
} }
fn get_classname_mapping(&self, client: &ureq::Agent) -> IndexMap<String, String> { fn get_classname_mapping(&self, client: &ureq::Agent) -> IndexMap<String, String> {
let mut mapping = IndexMap::new(); let mut mapping = IndexMap::new();
@ -241,9 +241,7 @@ impl DataSource for KBDataSource {
} }
}; };
let mut blocks = vec![]; let mut blocks = vec![];
let mut winrate = 0.0;
if !data.builds2.is_empty() { if !data.builds2.is_empty() {
winrate = (data.builds2[0].wins / data.builds2[0].games) * 100.;
let mut starting_items: Vec<Item> = vec![]; let mut starting_items: Vec<Item> = vec![];
if data.builds2[0].start_item0.item_id != 0 { if data.builds2[0].start_item0.item_id != 0 {
starting_items.push(Item { starting_items.push(Item {
@ -338,15 +336,16 @@ impl DataSource for KBDataSource {
), ),
items: final_items 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(( None
blocks,
Stat {
win_rate: winrate,
games: data.builds2[0].games as u32,
kda: 0.0,
},
))
} }
} }