This commit is contained in:
parent
0982c30f7a
commit
d854da599f
4 changed files with 54 additions and 34 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -210,9 +210,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.105"
|
version = "0.2.106"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013"
|
checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::Champion;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::{json, Value};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
@ -19,14 +19,14 @@ struct ItemSet {
|
||||||
blocks: Vec<Value>,
|
blocks: Vec<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Build {
|
pub struct Build {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub type_: String,
|
pub type_: String,
|
||||||
pub items: Vec<Item>,
|
pub items: Vec<Item>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub count: u8,
|
pub count: u8,
|
||||||
|
@ -50,6 +50,13 @@ pub trait DataSource {
|
||||||
champion: &Champion,
|
champion: &Champion,
|
||||||
) -> IndexMap<u32, Vec<String>>;
|
) -> IndexMap<u32, Vec<String>>;
|
||||||
|
|
||||||
|
fn make_item_set(&self, items: Vec<&str>, label: String) -> Value {
|
||||||
|
json!({
|
||||||
|
"items": items.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
|
||||||
|
"type": label
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn get_champ_data_with_win_pourcentage(
|
fn get_champ_data_with_win_pourcentage(
|
||||||
&self,
|
&self,
|
||||||
champ: &ChampInfo,
|
champ: &ChampInfo,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde_json::{json, Value};
|
use serde_json::Value;
|
||||||
|
|
||||||
use crate::data_source::{DataSource, Stat};
|
use crate::data_source::{DataSource, Stat};
|
||||||
use crate::ChampInfo;
|
use crate::ChampInfo;
|
||||||
|
@ -44,7 +44,7 @@ impl DataSource for MSDataSource {
|
||||||
|
|
||||||
let id = champion.data.get(key).unwrap().key.parse::<u32>().unwrap();
|
let id = champion.data.get(key).unwrap().key.parse::<u32>().unwrap();
|
||||||
|
|
||||||
champs.insert(id, vec![role.to_string()]);
|
champs.insert(id, vec![role.to_uppercase()]);
|
||||||
|
|
||||||
let next = page[p..].find(CHAMP_PATTERN);
|
let next = page[p..].find(CHAMP_PATTERN);
|
||||||
if let Some(n) = next {
|
if let Some(n) = next {
|
||||||
|
@ -65,19 +65,27 @@ 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
|
let rep = client
|
||||||
.get(
|
.get(
|
||||||
format!(
|
format!(
|
||||||
"https://www.metasrc.com/5v5/champion/{}/{}",
|
"https://www.metasrc.com/5v5/champion/{}/{}",
|
||||||
champ.id.to_lowercase(),
|
champ.id.to_lowercase(),
|
||||||
positions[0]
|
positions[0].to_lowercase()
|
||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
)
|
)
|
||||||
.call()
|
.call();
|
||||||
.unwrap()
|
if let Ok(p) = rep {
|
||||||
.into_string()
|
let page = p.into_string().unwrap();
|
||||||
.unwrap();
|
|
||||||
|
let mut pos = page.find("Patch ").unwrap();
|
||||||
|
let patch = &page[pos + 6..pos + 11];
|
||||||
|
|
||||||
|
pos = page.find("Win Rate:").unwrap();
|
||||||
|
let win_rate: f64 = (&page[pos + 26..pos + 31]).parse().unwrap();
|
||||||
|
|
||||||
|
pos = page.find("KDA:").unwrap();
|
||||||
|
let kda: f64 = (&page[pos + 21..pos + 25]).parse().unwrap();
|
||||||
|
|
||||||
let mut items = vec![];
|
let mut items = vec![];
|
||||||
|
|
||||||
|
@ -96,10 +104,17 @@ impl DataSource for MSDataSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builds.push((positions[0].to_owned(), vec![json!({
|
builds.push((
|
||||||
"items": items.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
|
positions[0].to_owned(),
|
||||||
"type": "Set"
|
vec![self.make_item_set(items, "Set".to_owned())],
|
||||||
})], Stat{win_rate:0.0,games:1,kda:0.0,patch:"".to_string()}));
|
Stat {
|
||||||
|
win_rate,
|
||||||
|
games: 1,
|
||||||
|
kda,
|
||||||
|
patch: patch.to_owned(),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
builds
|
builds
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use serde_json::{json, Value};
|
use serde_json::Value;
|
||||||
|
|
||||||
use crate::data_source::{DataSource, Stat};
|
use crate::data_source::{DataSource, Stat};
|
||||||
use crate::ChampInfo;
|
use crate::ChampInfo;
|
||||||
|
@ -73,7 +73,7 @@ impl DataSource for PBDataSource {
|
||||||
for build in rep {
|
for build in rep {
|
||||||
let pos = build.find("/players").unwrap();
|
let pos = build.find("/players").unwrap();
|
||||||
let tmp = &build[pos..];
|
let tmp = &build[pos..];
|
||||||
let name = &tmp[tmp.find(">").unwrap() + 1..tmp.find("<").unwrap()];
|
let name = &tmp[tmp.find('>').unwrap() + 1..tmp.find('<').unwrap()];
|
||||||
|
|
||||||
let mut items = vec![];
|
let mut items = vec![];
|
||||||
let mut build = &build[build.find("'items'").unwrap()..];
|
let mut build = &build[build.find("'items'").unwrap()..];
|
||||||
|
@ -85,9 +85,7 @@ impl DataSource for PBDataSource {
|
||||||
build = &build[end + 20..];
|
build = &build[end + 20..];
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks.push(json!({
|
blocks.push(self.make_item_set(items, name.to_string()));
|
||||||
"items": items.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
|
|
||||||
"type": format!("{}", name)}));
|
|
||||||
}
|
}
|
||||||
builds.push((
|
builds.push((
|
||||||
positions[0].to_owned(),
|
positions[0].to_owned(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue