From 9ece9e2da557ff20e11c95ce5a8322190af4f090 Mon Sep 17 00:00:00 2001 From: Sakuhl <2012collector@gmail.com> Date: Fri, 2 Mar 2018 14:22:08 +0100 Subject: [PATCH] Create example --- Cargo.toml | 5 ++++- examples/last-join.rs | 34 ++++++++++++++++++++++++++++++++++ src/lib.rs | 17 ----------------- src/main.rs | 15 --------------- 4 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 examples/last-join.rs delete mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml index d3bc2c8..11e9681 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -authors = ["Sakuhl <2012collector@gmail.com>"] +authors = ["FliegendeWurst <2012gdwu@web.de>", "Sakuhl <2012collector@gmail.com>"] name = "wynncraft" version = "0.1.0" @@ -9,3 +9,6 @@ reqwest = "0.8.2" serde = "1.0.27" serde_derive = "1.0.27" serde_json = "1.0.9" + +[dev-dependencies] +chrono = "0.4.0" \ No newline at end of file diff --git a/examples/last-join.rs b/examples/last-join.rs new file mode 100644 index 0000000..4d7ccba --- /dev/null +++ b/examples/last-join.rs @@ -0,0 +1,34 @@ +extern crate wynncraft; + +extern crate chrono; +use chrono::prelude::*; + +use std::env; + +fn main() { + let args = env::args().collect::>(); + match args.get(1).map(|x| &**x) { + Some("player-lastjoin") if args.len() > 2 => { + for name in &args[2..] { + println!("{}: {:?}", name, wynncraft::player(name).unwrap().last_join_friendly); + } + }, + Some("guild-player-lastjoin") if args.len() > 2 => { + for guild_name in &args[2..] { + for name in wynncraft::guild(guild_name).unwrap().unwrap().members.iter().map(|x| &x.name) { + let player = wynncraft::player(name).unwrap(); + let time = player.last_join.replace(' ', "T") + "+00:00"; + //println!("parsing {}", time); + let joined: DateTime = time.parse().unwrap(); // TODO: timezone? + let now = Local::now(); + println!("{}: {:?} -> {:?} days ago", + name, + player.last_join_friendly, + now.signed_duration_since(joined).num_days() + ); + } + } + }, + _ => {} // TODO + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 6ac2291..48ce4b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,18 +49,6 @@ pub fn guild_list() -> Result, Error> { } } -pub fn guild_by_prefix(prefix: &str) -> Result, Error> { - let top_100 = guild_leaderboard()?; - - for guild in top_100.data.into_iter() { - if guild.prefix.to_lowercase() == prefix.to_lowercase() { - return Ok(Some(guild)); - } - } - - Ok(None) -} - pub fn guild_leaderboard() -> Result { let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=statsLeaderboard&type=guild&timeframe=alltime")?.error_for_status()?.text()?; @@ -238,9 +226,4 @@ mod tests { fn guild_list() { ::guild_list().unwrap(); } - - #[test] - fn guild_prefix() { - ::guild_by_prefix("Two").unwrap(); - } } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 7074486..0000000 --- a/src/main.rs +++ /dev/null @@ -1,15 +0,0 @@ -extern crate wynncraft; - -use std::env; - -fn main() { - let args = env::args().collect::>(); - match args.get(1).map(|x| &**x) { - Some("player-lastjoin") if args.len() > 2 => { - for name in &args[2..] { - println!("{}: {:?}", name, wynncraft::player(name).unwrap().last_join_friendly); - } - }, - _ => {} // TODO - } -} \ No newline at end of file