MS: Find items
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
nyyu 2021-04-08 14:07:23 +02:00
parent 01897c8844
commit 7578c0801b

View file

@ -1,5 +1,5 @@
use indexmap::IndexMap; use indexmap::IndexMap;
use serde_json::{Value}; use serde_json::{json, Value};
use crate::data_source::{DataSource, Stat}; use crate::data_source::{DataSource, Stat};
use crate::ChampInfo; use crate::ChampInfo;
@ -63,6 +63,42 @@ impl DataSource for MSDataSource {
) -> Vec<(String, Vec<Value>, Stat)> { ) -> Vec<(String, Vec<Value>, Stat)> {
let mut builds = vec![]; 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<usize> = 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::<Vec<Value>>(),
"type": "Set"
})], Stat{win_rate:0.0,games:1,kda:0.0,patch:"".to_string()}));
builds builds
} }
} }