This commit is contained in:
parent
3fade08679
commit
71512c08e6
3 changed files with 34 additions and 17 deletions
|
@ -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(),
|
||||
},
|
||||
));
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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 rep: Vec<String> = serde_json::from_str(&page.into_string().unwrap()).unwrap();
|
||||
|
||||
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 = &str[str.find("'items'").unwrap()..];
|
||||
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();
|
||||
let end = build.find('"').unwrap();
|
||||
items.push(&build[..end]);
|
||||
build = &build[end + 20..];
|
||||
}
|
||||
|
||||
builds.push((positions[0].to_owned(), vec![json!({
|
||||
blocks.push(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()}));
|
||||
"type": format!("{}", name)}));
|
||||
}
|
||||
builds.push((
|
||||
positions[0].to_owned(),
|
||||
blocks,
|
||||
Stat {
|
||||
win_rate: 0.0,
|
||||
games: 1,
|
||||
kda: 0.0,
|
||||
patch: "".to_string(),
|
||||
},
|
||||
));
|
||||
}
|
||||
builds
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue