This commit is contained in:
parent
9f6170b234
commit
7bdcf52c47
33
Cargo.lock
generated
33
Cargo.lock
generated
@ -1,14 +1,5 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
@ -72,7 +63,6 @@ dependencies = [
|
||||
"indexmap",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"regex",
|
||||
"select",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
@ -280,12 +270,6 @@ version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
|
||||
|
||||
[[package]]
|
||||
name = "new_debug_unreachable"
|
||||
version = "1.0.4"
|
||||
@ -442,23 +426,6 @@ dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "54fd1046a3107eb58f42de31d656fee6853e5d276c455fd943742dce89fc3dd3"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.16.20"
|
||||
|
@ -8,7 +8,6 @@ version = "0.1.0"
|
||||
indexmap = {version = "1.6", features = ["serde-1"]}
|
||||
lazy_static = "1.4"
|
||||
log = "0.4"
|
||||
regex = "1.4"
|
||||
select = "0.5"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
|
@ -1,6 +1,5 @@
|
||||
use indexmap::IndexMap;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use serde_derive::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
use std::collections::HashMap;
|
||||
@ -90,6 +89,13 @@ impl CGGDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_json(pattern: &str, page: &str) -> String {
|
||||
|
||||
let json = page[page.find(pattern).unwrap()+pattern.len()..].to_owned();
|
||||
json[..json.find("};").unwrap()+1].replace("undefined", "null").to_owned()
|
||||
}
|
||||
|
||||
|
||||
impl DataSource for CGGDataSource {
|
||||
fn get_alias(&self) -> &str {
|
||||
"CGG"
|
||||
@ -104,23 +110,14 @@ impl DataSource for CGGDataSource {
|
||||
client: &ureq::Agent,
|
||||
) -> (IndexMap<String, Vec<String>>, String) {
|
||||
let req = client.get("https://champion.gg").call().unwrap();
|
||||
|
||||
lazy_static! {
|
||||
static ref RE: Regex =
|
||||
Regex::new(r"(?m)^\s+window.__PRELOADED_STATE__ = (.*);$").unwrap();
|
||||
static ref RE2: Regex =
|
||||
Regex::new(r"(?m)^\s+window.__FLASH_CMS_APOLLO_STATE__ = (.*);$").unwrap();
|
||||
}
|
||||
|
||||
let page = &req.into_string().unwrap();
|
||||
|
||||
let datas: BuildResponse =
|
||||
serde_json::from_str(&RE.captures(&page).unwrap()[1].replace("undefined", "null"))
|
||||
.unwrap();
|
||||
serde_json::from_str(&extract_json("window.__PRELOADED_STATE__ = ", &page)).unwrap();
|
||||
|
||||
let champs_stats: HashMap<String, ChampStat> =
|
||||
serde_json::from_str(&RE2.captures(&page).unwrap()[1].replace("undefined", "null"))
|
||||
.unwrap();
|
||||
serde_json::from_str(&extract_json("window.__FLASH_CMS_APOLLO_STATE__ = ", &page)).unwrap();
|
||||
|
||||
for entry in champs_stats.iter() {
|
||||
CHAMPIONS_STATS
|
||||
.lock()
|
||||
|
@ -3,7 +3,6 @@ use crate::data_source::{Build, DataSource, Item, Stat};
|
||||
use crate::time::Duration;
|
||||
use crate::ChampInfo;
|
||||
use indexmap::IndexMap;
|
||||
use regex::Regex;
|
||||
use serde_derive::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
@ -102,24 +101,26 @@ impl KBDataSource {
|
||||
}
|
||||
|
||||
// It will be better to use Result...
|
||||
fn get_auth_token(&self, client: &ureq::Agent) -> Option<String> {
|
||||
let bundle = match client.get("https://koreanbuilds.net/bundle.js").call() {
|
||||
fn get_auth_token(&self, client: &ureq::Agent) -> Option<String> {
|
||||
let mut bundle = match client.get("https://koreanbuilds.net/bundle.js").call() {
|
||||
Ok(resp) => match resp.into_string() {
|
||||
Ok(val) => val,
|
||||
Err(_) => return None,
|
||||
},
|
||||
Err(_) => return None,
|
||||
};
|
||||
let regex = match Regex::new(r##"Authorization:\s*"(\w+)""##) {
|
||||
Ok(reg) => reg,
|
||||
Err(_) => return None,
|
||||
};
|
||||
let result = match regex.captures(&bundle) {
|
||||
Some(res) => res,
|
||||
let auth_position = match bundle.find("Authorization") {
|
||||
Some(position) => position,
|
||||
None => return None,
|
||||
};
|
||||
return match result.get(1) {
|
||||
Some(token) => Some(token.as_str().to_string()),
|
||||
bundle = (&bundle[(auth_position + 13)..]).to_string();
|
||||
let q_position = match bundle.find("\"") {
|
||||
Some(position) => position,
|
||||
None => return None,
|
||||
};
|
||||
bundle = (&bundle[(q_position + 1)..]).to_string();
|
||||
return match bundle.find("\"") {
|
||||
Some(position) => Some((&bundle[..position]).to_string()),
|
||||
None => None,
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user