2018-06-16 10:48:46 +02:00
|
|
|
extern crate indexmap;
|
|
|
|
extern crate lazy_static;
|
|
|
|
extern crate log;
|
|
|
|
extern crate regex;
|
|
|
|
extern crate reqwest;
|
|
|
|
extern crate select;
|
|
|
|
extern crate serde;
|
|
|
|
extern crate serde_json;
|
|
|
|
extern crate simple_logger;
|
|
|
|
extern crate winreg;
|
|
|
|
|
|
|
|
use indexmap::IndexMap;
|
|
|
|
use regex::Regex;
|
|
|
|
use select::document::Document;
|
|
|
|
use select::predicate::{Class, Name};
|
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
use data_source::DataSource;
|
|
|
|
|
|
|
|
pub struct CGGDataSource;
|
|
|
|
impl DataSource for CGGDataSource {
|
|
|
|
fn get_champs_with_positions_and_patch(
|
2018-06-16 12:48:14 +02:00
|
|
|
&self,
|
2018-06-16 10:48:46 +02:00
|
|
|
client: &reqwest::Client,
|
|
|
|
) -> (IndexMap<String, Vec<String>>, String) {
|
|
|
|
let page = client
|
|
|
|
.get("https://champion.gg")
|
|
|
|
.send()
|
|
|
|
.unwrap()
|
|
|
|
.text()
|
|
|
|
.unwrap();
|
|
|
|
let document = Document::from(&*page);
|
|
|
|
|
|
|
|
let patch = document
|
|
|
|
.find(Class("analysis-holder"))
|
|
|
|
.next()
|
|
|
|
.unwrap()
|
|
|
|
.find(Name("strong"))
|
|
|
|
.next()
|
|
|
|
.unwrap()
|
|
|
|
.text();
|
|
|
|
|
|
|
|
let mut champions = IndexMap::new();
|
|
|
|
for node in document.find(Class("champ-height")) {
|
|
|
|
let id = node
|
|
|
|
.find(Class("home-champion"))
|
|
|
|
.next()
|
|
|
|
.unwrap()
|
|
|
|
.attr("class")
|
|
|
|
.unwrap()
|
|
|
|
.split(' ')
|
|
|
|
.last()
|
|
|
|
.unwrap()
|
|
|
|
.to_string();
|
|
|
|
let positions = node
|
|
|
|
.find(Name("a"))
|
|
|
|
.skip(1)
|
|
|
|
.map(|x| {
|
|
|
|
x.attr("href")
|
|
|
|
.unwrap()
|
|
|
|
.split('/')
|
|
|
|
.last()
|
|
|
|
.unwrap()
|
|
|
|
.to_string()
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
champions.insert(id, positions);
|
|
|
|
}
|
|
|
|
|
|
|
|
(champions, patch)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_champ_data(id: &str, position: &str, client: &reqwest::Client) -> Option<Value> {
|
|
|
|
let mut req = client
|
|
|
|
.get(&format!(
|
|
|
|
"https://champion.gg/champion/{}/{}?league=",
|
|
|
|
id, position
|
|
|
|
))
|
|
|
|
.send()
|
|
|
|
.unwrap();
|
|
|
|
if req.status().is_success() {
|
|
|
|
lazy_static! {
|
|
|
|
static ref RE: Regex =
|
|
|
|
Regex::new(r"(?m)^\s+matchupData\.championData = (.*)$").unwrap();
|
|
|
|
}
|
|
|
|
serde_json::from_str(&RE.captures(&req.text().unwrap())?[1]).unwrap()
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|