2021-04-08 13:55:10 +02:00
|
|
|
use indexmap::IndexMap;
|
2021-04-08 14:07:23 +02:00
|
|
|
use serde_json::{json, Value};
|
2021-04-08 13:55:10 +02:00
|
|
|
|
|
|
|
use crate::data_source::{DataSource, Stat};
|
|
|
|
use crate::ChampInfo;
|
|
|
|
use crate::Champion;
|
|
|
|
|
|
|
|
pub struct MSDataSource;
|
|
|
|
|
|
|
|
impl DataSource for MSDataSource {
|
|
|
|
fn get_alias(&self) -> &str {
|
|
|
|
"MS"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_timeout(&self) -> u64 {
|
|
|
|
300
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_champs_with_positions(
|
|
|
|
&self,
|
|
|
|
client: &ureq::Agent,
|
|
|
|
champion: &Champion,
|
|
|
|
) -> IndexMap<u32, Vec<String>> {
|
|
|
|
let mut champs = IndexMap::new();
|
|
|
|
|
|
|
|
let page = client
|
|
|
|
.get("https://www.metasrc.com/5v5")
|
|
|
|
.call()
|
|
|
|
.unwrap()
|
|
|
|
.into_string()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let mut pos: Option<usize> = page.find(" href=\"/5v5/champion/");
|
|
|
|
while let Some(mut p) = pos {
|
|
|
|
p += 21;
|
|
|
|
let role =
|
|
|
|
&page[p + page[p..].find('/').unwrap() + 1..p + page[p..].find('"').unwrap()];
|
|
|
|
|
|
|
|
let k = p + &page[p..].find("data-search-terms-like=\"").unwrap() + 24;
|
|
|
|
let pipe = k + &page[k..].find("|").unwrap() + 1;
|
|
|
|
let key = &page[pipe..pipe + &page[pipe..].find('"').unwrap()];
|
|
|
|
|
|
|
|
let id = champion.data.get(key).unwrap().key.parse::<u32>().unwrap();
|
|
|
|
|
|
|
|
champs.insert(id, vec![role.to_string()]);
|
|
|
|
|
|
|
|
let next = page[p..].find(" href=\"/5v5/champion/");
|
|
|
|
if let Some(n) = next {
|
|
|
|
pos = Some(p + n);
|
|
|
|
} else {
|
|
|
|
pos = None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
champs
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_champ_data_with_win_pourcentage(
|
|
|
|
&self,
|
|
|
|
champ: &ChampInfo,
|
|
|
|
positions: &[String],
|
|
|
|
client: &ureq::Agent,
|
|
|
|
) -> Vec<(String, Vec<Value>, Stat)> {
|
|
|
|
let mut builds = vec![];
|
|
|
|
|
2021-04-08 14:07:23 +02:00
|
|
|
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()}));
|
|
|
|
|
2021-04-08 13:55:10 +02:00
|
|
|
builds
|
|
|
|
}
|
|
|
|
}
|