wynncraft/examples/last-join.rs

39 lines
977 B
Rust
Raw Normal View History

2018-03-02 13:22:08 +00:00
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..] {
2020-03-14 13:56:33 +00:00
println!("{}: {:?}", name, wynncraft::player(name).unwrap().meta.lastJoin);
2018-03-02 13:22:08 +00:00
}
},
Some("guild-player-lastjoin") if args.len() > 2 => {
2020-03-14 13:56:33 +00:00
let mut inactive = 0;
2018-03-02 13:22:08 +00:00
for guild_name in &args[2..] {
for name in wynncraft::guild(guild_name).unwrap().unwrap().members.iter().map(|x| &x.name) {
2020-03-14 13:56:33 +00:00
let days = wynncraft::player(name)
.map(|x| x.meta.lastJoin)
.map(|x| x.parse::<DateTime<FixedOffset>>().unwrap())
.map(|x| Local::now().signed_duration_since(x).num_days() as i64)
.unwrap_or(-1);
println!("{}: {:?} days ago",
2018-03-02 13:22:08 +00:00
name,
2020-03-14 13:56:33 +00:00
days
2018-03-02 13:22:08 +00:00
);
2020-03-14 13:56:33 +00:00
if days > 14 {
inactive += 1;
}
2018-03-02 13:22:08 +00:00
}
}
2020-03-14 13:56:33 +00:00
println!("--> {} inactive", inactive);
2018-03-02 13:22:08 +00:00
},
_ => {} // TODO
}
2020-03-14 13:56:33 +00:00
}