init rust version

This commit is contained in:
nyyu 2018-06-04 22:51:18 +02:00
commit ef8eef5058
4 changed files with 1145 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target/

1088
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

11
Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "CGGItemSets"
version = "0.1.0"
authors = ["nyyu <mail@nyyu.tk>"]
[dependencies]
log = "^0.4"
simple_logger = "^0.5"
serde = "^1.0"
serde_derive = "^1.0"
reqwest = "^0.8"

45
src/main.rs Normal file
View File

@ -0,0 +1,45 @@
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate log;
extern crate reqwest;
extern crate serde;
extern crate simple_logger;
use std::collections::HashMap;
use reqwest::header::{Headers, UserAgent};
#[derive(Deserialize)]
struct Realm {
v: String,
}
#[derive(Deserialize)]
struct Champion {
data: HashMap<String, ChampInfo>
}
#[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!("http://ddragon.leagueoflegends.com/cdn/{}/data/en_US/champion.json", realm.v)).send().unwrap().json().unwrap();
info!("LoL numbers of champs: {}", champion.data.len());
}