From 71512c08e6cb2454917b550acafd6eebd92da9ff Mon Sep 17 00:00:00 2001 From: nyyu Date: Sun, 31 Oct 2021 09:22:49 +0100 Subject: [PATCH] pb: 5 builds --- src/cgg_data_source.rs | 5 +++-- src/ms_data_source.rs | 1 - src/pb_data_source.rs | 45 +++++++++++++++++++++++++++++------------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/cgg_data_source.rs b/src/cgg_data_source.rs index 6e7623b..7c1a6ad 100644 --- a/src/cgg_data_source.rs +++ b/src/cgg_data_source.rs @@ -42,7 +42,7 @@ struct Stats { kills: u32, deaths: u32, wins: u32, - assists: u32 + assists: u32, } #[derive(Deserialize, Debug)] @@ -173,7 +173,8 @@ impl DataSource for CGGDataSource { Stat { win_rate: (champ.stats.wins as f64 / champ.stats.games as f64) * 100f64, games: champ.stats.games, - kda: (champ.stats.kills + champ.stats.assists) as f64 / champ.stats.deaths as f64, + kda: (champ.stats.kills + champ.stats.assists) as f64 + / champ.stats.deaths as f64, patch: champ.patch.to_owned(), }, )); diff --git a/src/ms_data_source.rs b/src/ms_data_source.rs index e8b37b6..8883272 100644 --- a/src/ms_data_source.rs +++ b/src/ms_data_source.rs @@ -10,7 +10,6 @@ pub struct MSDataSource; const CHAMP_PATTERN: &str = " href=\"https://www.metasrc.com/5v5/champion/"; impl DataSource for MSDataSource { - fn get_alias(&self) -> &str { "MS" } diff --git a/src/pb_data_source.rs b/src/pb_data_source.rs index 379f5e3..b42ba53 100644 --- a/src/pb_data_source.rs +++ b/src/pb_data_source.rs @@ -62,26 +62,43 @@ impl DataSource for PBDataSource { let mut builds = vec![]; let rep = client - .get(format!("https://www.probuilds.net/ajax/gamesLive?limit=1&sort=gameDate-desc&championId={}&olderThan=0&lane=®ion=", champ.key).as_str()) + .get(format!("https://www.probuilds.net/ajax/gamesLive?limit=5&sort=gameDate-desc&championId={}&olderThan=0&lane=®ion=", champ.key).as_str()) .set("Accept", "application/json") .call(); if let Ok(page) = rep { - let str = page.into_string().unwrap(); - let mut items = vec![]; - let mut build = &str[str.find("'items'").unwrap()..]; - while build.contains("items") { - let pos = build.find("data-id=").unwrap(); - build = &build[pos + 10..]; - let end = build.find('\\').unwrap(); - items.push(&build[..end]); - build = &build[end + 20..]; - } + let rep: Vec = serde_json::from_str(&page.into_string().unwrap()).unwrap(); - builds.push((positions[0].to_owned(), vec![json!({ + let mut blocks = vec![]; + for build in rep { + let pos = build.find("/players").unwrap(); + let tmp = &build[pos..]; + let name = &tmp[tmp.find(">").unwrap() + 1..tmp.find("<").unwrap()]; + + let mut items = vec![]; + let mut build = &build[build.find("'items'").unwrap()..]; + while build.contains("items") { + let pos = build.find("data-id=").unwrap(); + build = &build[pos + 10..]; + let end = build.find('"').unwrap(); + items.push(&build[..end]); + build = &build[end + 20..]; + } + + blocks.push(json!({ "items": items.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::>(), - "type": "Set" - })], Stat{win_rate:0.0,games:1,kda:0.0,patch:"".to_string()})); + "type": format!("{}", name)})); + } + builds.push(( + positions[0].to_owned(), + blocks, + Stat { + win_rate: 0.0, + games: 1, + kda: 0.0, + patch: "".to_string(), + }, + )); } builds }