CGGItemSets/src/ms_data_source.rs

68 lines
1.7 KiB
Rust

use indexmap::IndexMap;
use serde_json::{Value};
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![];
builds
}
}