use indexmap to keep order

This commit is contained in:
nyyu 2018-06-09 12:35:47 +02:00
parent 444f6333b5
commit f3503df2ec
3 changed files with 19 additions and 6 deletions

11
Cargo.lock generated
View file

@ -84,6 +84,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "cggitem_sets" name = "cggitem_sets"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -282,6 +283,14 @@ dependencies = [
"unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "indexmap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "iovec" name = "iovec"
version = "0.1.2" version = "0.1.2"
@ -751,6 +760,7 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -1235,6 +1245,7 @@ dependencies = [
"checksum hyper 0.11.27 (registry+https://github.com/rust-lang/crates.io-index)" = "34a590ca09d341e94cddf8e5af0bbccde205d5fbc2fa3c09dd67c7f85cea59d7" "checksum hyper 0.11.27 (registry+https://github.com/rust-lang/crates.io-index)" = "34a590ca09d341e94cddf8e5af0bbccde205d5fbc2fa3c09dd67c7f85cea59d7"
"checksum hyper-tls 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a5aa51f6ae9842239b0fac14af5f22123b8432b4cc774a44ff059fcba0f675ca" "checksum hyper-tls 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a5aa51f6ae9842239b0fac14af5f22123b8432b4cc774a44ff059fcba0f675ca"
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
"checksum indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08173ba1e906efb6538785a8844dd496f5d34f0a2d88038e95195172fc667220"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682" "checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"

View file

@ -8,9 +8,10 @@ log = "0.4"
simple_logger = "0.5" simple_logger = "0.5"
serde = "1.0" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
serde_json = "1.0" serde_json = { version = "1.0", features = ["preserve_order"] }
reqwest = "0.8" reqwest = "0.8"
select = { git = "https://github.com/utkarshkukreti/select.rs" } select = { git = "https://github.com/utkarshkukreti/select.rs" }
regex = "1.0" regex = "1.0"
lazy_static = "1.0" lazy_static = "1.0"
winreg = "0.5" winreg = "0.5"
indexmap = { version = "1.0", features = ["serde-1"] }

View file

@ -11,14 +11,15 @@ extern crate select;
extern crate simple_logger; extern crate simple_logger;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
extern crate indexmap;
extern crate winreg; extern crate winreg;
use indexmap::IndexMap;
use regex::Regex; use regex::Regex;
use reqwest::header::{Headers, UserAgent}; use reqwest::header::{Headers, UserAgent};
use select::document::Document; use select::document::Document;
use select::predicate::{Class, Name}; use select::predicate::{Class, Name};
use serde_json::Value; use serde_json::Value;
use std::collections::BTreeMap;
use std::path::PathBuf; use std::path::PathBuf;
use std::{fs, io, thread, time}; use std::{fs, io, thread, time};
use time::Duration; use time::Duration;
@ -31,7 +32,7 @@ struct Realm {
#[derive(Deserialize)] #[derive(Deserialize)]
struct Champion { struct Champion {
data: BTreeMap<String, ChampInfo>, data: IndexMap<String, ChampInfo>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -132,7 +133,7 @@ fn main() {
fn get_champs_with_positions_and_patch( fn get_champs_with_positions_and_patch(
client: &reqwest::Client, client: &reqwest::Client,
) -> (BTreeMap<String, Vec<String>>, String) { ) -> (IndexMap<String, Vec<String>>, String) {
let page = client let page = client
.get("https://champion.gg") .get("https://champion.gg")
.send() .send()
@ -150,7 +151,7 @@ fn get_champs_with_positions_and_patch(
.unwrap() .unwrap()
.text(); .text();
let mut champions = BTreeMap::new(); let mut champions = IndexMap::new();
for node in document.find(Class("champ-height")) { for node in document.find(Class("champ-height")) {
let id = node.find(Class("home-champion")) let id = node.find(Class("home-champion"))
.next() .next()