Add simple formatting
This commit is contained in:
parent
584d38761a
commit
43132a745d
3 changed files with 1410 additions and 2 deletions
1336
Cargo.lock
generated
Normal file
1336
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -5,3 +5,9 @@ authors = ["Stan Drozd <drozdziak1@gmail.com>"]
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
reqwest = "0.9.9"
|
||||
failure = "0.1.5"
|
||||
serde_derive = "1.0.87"
|
||||
serde = "1.0.87"
|
||||
serde_json = "1.0.38"
|
||||
colored = "1.7.0"
|
||||
|
|
70
src/main.rs
70
src/main.rs
|
@ -1,3 +1,69 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
use colored::*;
|
||||
use failure::Error;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
fn f64_to_u64_helper<'de, D: Deserializer<'de>>(d: D) -> Result<u64, D::Error> {
|
||||
Ok(f64::deserialize(d)? as u64)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
struct HsMember {
|
||||
#[serde(deserialize_with = "f64_to_u64_helper")]
|
||||
timestamp: u64,
|
||||
login: String,
|
||||
pretty_time: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
struct Response {
|
||||
pub kektops: u16,
|
||||
pub unknown: u16,
|
||||
pub esps: u16,
|
||||
pub users: Vec<HsMember>,
|
||||
pub vms: u16,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
let res = reqwest::get("https://at.hackerspace.pl/api")?.text()?;
|
||||
|
||||
let parsed: Response = serde_json::from_str(&res)?;
|
||||
|
||||
let logins: Vec<&str> = parsed
|
||||
.users
|
||||
.iter()
|
||||
.map(|member| member.login.as_str())
|
||||
.collect();
|
||||
|
||||
let members_pretty = if logins.len() > 0 {
|
||||
logins.as_slice().join(" | ")
|
||||
} else {
|
||||
"no-one".to_string()
|
||||
};
|
||||
|
||||
if parsed.users.len() > 0 {
|
||||
println!("{}: {}", "Members".green(), members_pretty);
|
||||
}
|
||||
|
||||
if parsed.unknown > 0 {
|
||||
println!("{}: {}", "Anons".yellow(), parsed.unknown);
|
||||
}
|
||||
|
||||
if parsed.kektops > 0 {
|
||||
println!("{}: {}", "Kektops".blue(), parsed.kektops);
|
||||
}
|
||||
|
||||
if parsed.esps > 0 {
|
||||
println!("{}: {}", "ESPs".blue(), parsed.esps);
|
||||
}
|
||||
|
||||
if parsed.vms > 0 {
|
||||
println!("{}: {}", "VMs".blue(), parsed.vms);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue