diff --git a/src/ms_data_source.rs b/src/ms_data_source.rs index 10acd1a..63e1ab3 100644 --- a/src/ms_data_source.rs +++ b/src/ms_data_source.rs @@ -1,5 +1,5 @@ use indexmap::IndexMap; -use serde_json::{Value}; +use serde_json::{json, Value}; use crate::data_source::{DataSource, Stat}; use crate::ChampInfo; @@ -63,6 +63,42 @@ impl DataSource for MSDataSource { ) -> Vec<(String, Vec, Stat)> { let mut builds = vec![]; + let page = client + .get( + format!( + "https://www.metasrc.com/5v5/champion/{}/{}", + champ.id.to_lowercase(), + positions[0] + ) + .as_str(), + ) + .call() + .unwrap() + .into_string() + .unwrap(); + + let mut items = vec![]; + + let mut pos: Option = page.find("/item/"); + while let Some(mut p) = pos { + p += 6; + let i = &page[p..p + &page[p..].find('.').unwrap()]; + + items.push(i); + + let next = page[p..].find("/item/"); + if let Some(n) = next { + pos = Some(p + n); + } else { + pos = None; + } + } + + builds.push((positions[0].to_owned(), vec![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()})); + builds } }