fix: remove PBDatasource dead
This commit is contained in:
parent
9401384844
commit
16ca1a1545
2 changed files with 0 additions and 106 deletions
|
@ -22,12 +22,10 @@ use winreg::RegKey;
|
||||||
mod data_source;
|
mod data_source;
|
||||||
mod kb_data_source;
|
mod kb_data_source;
|
||||||
mod ms_data_source;
|
mod ms_data_source;
|
||||||
mod pb_data_source;
|
|
||||||
|
|
||||||
use data_source::DataSource;
|
use data_source::DataSource;
|
||||||
use kb_data_source::KBDataSource;
|
use kb_data_source::KBDataSource;
|
||||||
use ms_data_source::MSDataSource;
|
use ms_data_source::MSDataSource;
|
||||||
use pb_data_source::PBDataSource;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Realm {
|
struct Realm {
|
||||||
|
@ -101,7 +99,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
info!("LoL numbers of champs: {}", champion.data.len());
|
info!("LoL numbers of champs: {}", champion.data.len());
|
||||||
|
|
||||||
let data_sources: Vec<Box<dyn DataSource + Sync + Send>> = vec![
|
let data_sources: Vec<Box<dyn DataSource + Sync + Send>> = vec![
|
||||||
Box::new(PBDataSource),
|
|
||||||
Box::new(KBDataSource::new()),
|
Box::new(KBDataSource::new()),
|
||||||
Box::new(MSDataSource),
|
Box::new(MSDataSource),
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,103 +0,0 @@
|
||||||
use indexmap::IndexMap;
|
|
||||||
use serde_derive::Deserialize;
|
|
||||||
use serde_json::Value;
|
|
||||||
|
|
||||||
use crate::data_source::{DataSource, Stat};
|
|
||||||
use crate::ChampInfo;
|
|
||||||
use crate::Champion as ChampionLoL;
|
|
||||||
|
|
||||||
pub struct PBDataSource;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct ChampionResponse {
|
|
||||||
champions: Vec<Champion>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct Champion {
|
|
||||||
key: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DataSource for PBDataSource {
|
|
||||||
fn get_alias(&self) -> &str {
|
|
||||||
"PB"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_timeout(&self) -> u64 {
|
|
||||||
300
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_champs_with_positions(
|
|
||||||
&self,
|
|
||||||
client: &ureq::Agent,
|
|
||||||
_champion: &ChampionLoL,
|
|
||||||
) -> IndexMap<u32, Vec<String>> {
|
|
||||||
let mut champs = IndexMap::new();
|
|
||||||
|
|
||||||
let page = client
|
|
||||||
.get("https://www.probuilds.net/ajax/championListNew")
|
|
||||||
.set("Accept", "application/json")
|
|
||||||
.call()
|
|
||||||
.unwrap()
|
|
||||||
.into_string()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let data: ChampionResponse = serde_json::from_str(&page).unwrap();
|
|
||||||
|
|
||||||
for champ in data.champions {
|
|
||||||
if let Some(k) = champ.key {
|
|
||||||
champs.insert(k.parse::<u32>().unwrap(), vec!["ANY".to_owned()]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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![];
|
|
||||||
|
|
||||||
let rep = client
|
|
||||||
.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 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 = &build[build.find("'items'").unwrap()..];
|
|
||||||
while build.contains("items") {
|
|
||||||
let pos = build.find("data-id=").unwrap();
|
|
||||||
build = &build[pos + 9..];
|
|
||||||
let end = build.find('"').unwrap();
|
|
||||||
items.push(&build[..end]);
|
|
||||||
build = &build[end + 18..];
|
|
||||||
}
|
|
||||||
|
|
||||||
blocks.push(self.make_item_set(items, name.to_string()));
|
|
||||||
}
|
|
||||||
builds.push((
|
|
||||||
positions[0].to_owned(),
|
|
||||||
blocks,
|
|
||||||
Stat {
|
|
||||||
win_rate: 0.0,
|
|
||||||
games: 1,
|
|
||||||
kda: 0.0,
|
|
||||||
patch: "".to_string(),
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
|
||||||
builds
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue