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

This commit is contained in:
nyyu 2021-10-29 19:59:29 +02:00
parent 4651f3bc02
commit 8f0af3e76b
2 changed files with 30 additions and 27 deletions

View file

@ -199,7 +199,7 @@ impl DataSource for CGGDataSource {
} }
} }
let stat = champs_stats.get(&key).unwrap(); if let Some(stat) = champs_stats.get(&key) {
data.push(( data.push((
position.to_owned(), position.to_owned(),
blocks, blocks,
@ -212,6 +212,7 @@ impl DataSource for CGGDataSource {
)); ));
} }
} }
}
data data
} }
} }

View file

@ -61,13 +61,15 @@ impl DataSource for PBDataSource {
) -> Vec<(String, Vec<Value>, Stat)> { ) -> Vec<(String, Vec<Value>, Stat)> {
let mut builds = vec![]; let mut builds = vec![];
let page = client let rep = client
.get(format!("https://www.probuilds.net/ajax/games?limit=1&sort=gameDate-desc&championId={}&olderThan=0&lane=&region=", champ.key).as_str()) .get(format!("https://www.probuilds.net/ajax/games?limit=1&sort=gameDate-desc&championId={}&olderThan=0&lane=&region=", champ.key).as_str())
.set("Accept", "application/json") .set("Accept", "application/json")
.call().unwrap().into_string().unwrap(); .call();
if let Ok(page) = rep {
let str = page.into_string().unwrap();
let mut items = vec![]; let mut items = vec![];
let mut build = &page[page.find("'items'").unwrap()..]; let mut build = &str[str.find("'items'").unwrap()..];
while build.contains("items") { while build.contains("items") {
let pos = build.find("data-id=").unwrap(); let pos = build.find("data-id=").unwrap();
build = &build[pos + 10..]; build = &build[pos + 10..];
@ -80,7 +82,7 @@ impl DataSource for PBDataSource {
"items": items.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(), "items": items.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
"type": "Set" "type": "Set"
})], Stat{win_rate:0.0,games:1,kda:0.0,patch:"".to_string()})); })], Stat{win_rate:0.0,games:1,kda:0.0,patch:"".to_string()}));
}
builds builds
} }
} }