remove bloat and fix error champion gg if fail
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nyyu 2021-08-23 00:12:29 +02:00
parent fdf65c0963
commit 5ee2d9dad2
3 changed files with 44 additions and 46 deletions

22
Cargo.lock generated
View file

@ -139,15 +139,6 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "encoding_rs"
version = "0.8.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065"
dependencies = [
"cfg-if",
]
[[package]]
name = "form_urlencoded"
version = "1.0.1"
@ -198,9 +189,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "0.4.7"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "js-sys"
@ -383,15 +374,15 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.127"
version = "1.0.128"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f03b9878abf6d14e6779d3f24f07b2cfa90352cfec4acc5aab8f1ac7f146fae8"
checksum = "1056a0db1978e9dbf0f6e4fca677f6f9143dc1c19de346f22cac23e422196834"
[[package]]
name = "serde_derive"
version = "1.0.127"
version = "1.0.128"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a024926d3432516606328597e0f224a51355a493b49fdd67e9209187cbe55ecc"
checksum = "13af2fbb8b60a8950d6c72a56d2095c28870367cc8e10c55e9745bac4995a2c4"
dependencies = [
"proc-macro2",
"quote",
@ -501,7 +492,6 @@ checksum = "2475a6781e9bc546e7b64f4013d2f4032c8c6a40fcffd7c6f4ee734a890972ab"
dependencies = [
"base64",
"chunked_transfer",
"encoding_rs",
"log",
"once_cell",
"rustls",

View file

@ -4,6 +4,7 @@ edition = "2018"
resolver = "2"
name = "cggitem_sets"
version = "1.0.0"
include = ["src/**/*"]
[dependencies]
indexmap = {version = "1.6", features = ["serde-1", "rayon"]}
@ -14,7 +15,7 @@ serde = "1.0"
serde_derive = "1.0"
serde_json = {version = "1.0", features = ["preserve_order"]}
simple_logger = "1.11"
ureq = {version = "2.0", features = ["json", "charset"]}
ureq = {version = "2.0", features = ["json"]}
[target.'cfg(windows)'.dependencies]
winreg = "0.8"

View file

@ -1,5 +1,6 @@
use indexmap::IndexMap;
use lazy_static::lazy_static;
use log::error;
use serde_derive::Deserialize;
use serde_json::{json, Value};
use std::collections::HashMap;
@ -109,38 +110,44 @@ impl DataSource for CGGDataSource {
client: &ureq::Agent,
_champion: &Champion,
) -> IndexMap<u32, Vec<String>> {
let req = client.get("https://champion.gg").call().unwrap();
let page = &req.into_string().unwrap();
let datas: BuildResponse =
serde_json::from_str(&extract_json("window.__PRELOADED_STATE__ = ", page)).unwrap();
let champs_stats: HashMap<String, ChampStat> =
serde_json::from_str(&extract_json("window.__FLASH_CMS_APOLLO_STATE__ = ", page))
.unwrap();
for entry in champs_stats.iter() {
CHAMPIONS_STATS
.lock()
.unwrap()
.insert(entry.0.to_owned(), entry.1.to_owned());
}
let mut champions: IndexMap<u32, Vec<String>> = IndexMap::new();
for champ in &datas.lol.champions_report {
let id = champ.champion_id;
if champions.contains_key(&id) {
let mut roles = champions.get(&id).unwrap().to_owned();
roles.push(champ.role.to_owned());
champions.insert(id, roles);
} else {
champions.insert(id, vec![champ.role.to_owned()]);
match client.get("https://champion.gg").call() {
Ok(req) => {
let page = &req.into_string().unwrap();
let datas: BuildResponse =
serde_json::from_str(&extract_json("window.__PRELOADED_STATE__ = ", page))
.unwrap();
let champs_stats: HashMap<String, ChampStat> = serde_json::from_str(&extract_json(
"window.__FLASH_CMS_APOLLO_STATE__ = ",
page,
))
.unwrap();
for entry in champs_stats.iter() {
CHAMPIONS_STATS
.lock()
.unwrap()
.insert(entry.0.to_owned(), entry.1.to_owned());
}
for champ in &datas.lol.champions_report {
let id = champ.champion_id;
if champions.contains_key(&id) {
let mut roles = champions.get(&id).unwrap().to_owned();
roles.push(champ.role.to_owned());
champions.insert(id, roles);
} else {
champions.insert(id, vec![champ.role.to_owned()]);
}
}
for report in datas.lol.champions_report {
CHAMPIONS_REPORT.lock().unwrap().push(report);
}
}
Err(e) => error!("Error retrieving data: {}", e),
}
for report in datas.lol.champions_report {
CHAMPIONS_REPORT.lock().unwrap().push(report);
}
champions
}