#[macro_use] extern crate serde_derive; #[macro_use] extern crate log; extern crate reqwest; extern crate serde; extern crate simple_logger; extern crate kuchiki; use std::collections::HashMap; use reqwest::header::{Headers, UserAgent}; use kuchiki::traits::*; #[derive(Deserialize)] struct Realm { v: String, } #[derive(Deserialize)] struct Champion { data: HashMap } #[derive(Deserialize)] struct ChampInfo { id: String, } const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"; fn main() { simple_logger::init_with_level(log::Level::Info).unwrap(); info!("CGG Item Sets"); let mut headers = Headers::new(); headers.set(UserAgent::new(USER_AGENT)); let client = reqwest::Client::builder().default_headers(headers).build().unwrap(); let realm: Realm = client.get("https://ddragon.leagueoflegends.com/realms/euw.json").send().unwrap().json().unwrap(); info!("LoL version: {}", realm.v); let champion: Champion = client.get(&format!("https://ddragon.leagueoflegends.com/cdn/{}/data/en_US/champion.json", realm.v)).send().unwrap().json().unwrap(); info!("LoL numbers of champs: {}", champion.data.len()); let (champs, patch) = get_champs_with_positions_and_patch(client); info!("CGG version: {}", patch); info!("CGG numbers of champs: {}", champs.len()); for (name, positions) in champs { info!("Champ: {}", name); for pos in positions { info!("{}", pos); } } } fn get_champs_with_positions_and_patch(client: reqwest::Client) -> (HashMap>, String) { let page = client.get("https://champion.gg").send().unwrap().text().unwrap(); let document = kuchiki::parse_html().one(page); let strong = document.select(".analysis-holder").unwrap().next().unwrap().as_node().select("strong").unwrap().next().unwrap().as_node().first_child().unwrap(); let patch = strong.as_text().unwrap().borrow(); let mut champions = HashMap::new(); for css_match in document.select(".champ-height").unwrap() { let div = css_match.as_node(); let champ_span = div.select(".champion-name").unwrap().next().unwrap().as_node().first_child().unwrap(); let name = champ_span.as_text().unwrap().borrow(); let mut positions = Vec::new(); for link_match in div.select("a").unwrap().skip(1) { let attributes = link_match.attributes.borrow(); let pos = attributes.get("href").unwrap().split("/").last().unwrap(); positions.push(format!("{}", pos)); } champions.insert(format!("{}", name), positions); } (champions, format!("{}", patch)) }