wynncraft/examples/last-join.rs
2018-03-02 14:22:08 +01:00

34 lines
985 B
Rust

extern crate wynncraft;
extern crate chrono;
use chrono::prelude::*;
use std::env;
fn main() {
let args = env::args().collect::<Vec<_>>();
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<FixedOffset> = 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
}
}