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,17 +199,18 @@ 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,
Stat { Stat {
win_rate: stat.win_rate.unwrap(), win_rate: stat.win_rate.unwrap(),
games: stat.games.unwrap(), games: stat.games.unwrap(),
kda: stat.kda.unwrap(), kda: stat.kda.unwrap(),
patch: champ.patch.to_owned(), patch: champ.patch.to_owned(),
}, },
)); ));
}
} }
} }
data data

View file

@ -61,26 +61,28 @@ 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();
let mut items = vec![]; if let Ok(page) = rep {
let mut build = &page[page.find("'items'").unwrap()..]; let str = page.into_string().unwrap();
while build.contains("items") { let mut items = vec![];
let pos = build.find("data-id=").unwrap(); let mut build = &str[str.find("'items'").unwrap()..];
build = &build[pos + 10..]; while build.contains("items") {
let end = build.find('\\').unwrap(); let pos = build.find("data-id=").unwrap();
items.push(&build[..end]); build = &build[pos + 10..];
build = &build[end + 20..]; let end = build.find('\\').unwrap();
items.push(&build[..end]);
build = &build[end + 20..];
}
builds.push((positions[0].to_owned(), vec![json!({
"items": items.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
"type": "Set"
})], Stat{win_rate:0.0,games:1,kda:0.0,patch:"".to_string()}));
} }
builds.push((positions[0].to_owned(), vec![json!({
"items": items.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
"type": "Set"
})], Stat{win_rate:0.0,games:1,kda:0.0,patch:"".to_string()}));
builds builds
} }
} }