imgurs/src/cli/mod.rs

78 lines
2.0 KiB
Rust
Raw Normal View History

pub mod clipboard;
2022-01-22 21:02:51 +00:00
pub mod credits;
pub mod delete_image;
2022-01-23 12:05:32 +00:00
pub mod info_image;
2022-01-22 22:10:11 +00:00
pub mod parse;
2022-01-22 21:14:26 +00:00
pub mod upload_image;
pub mod webhook;
2022-01-23 12:05:32 +00:00
2022-01-25 16:13:43 +00:00
use chrono::{prelude::DateTime, Utc};
use colored::Colorize;
2022-02-27 10:39:28 +00:00
use imgurs::api::ImageInfo;
use std::time::{Duration, UNIX_EPOCH};
2022-01-23 12:05:32 +00:00
pub fn print_image_info(i: ImageInfo) {
2022-01-23 12:05:32 +00:00
let d = UNIX_EPOCH + Duration::from_secs(i.data.datetime.try_into().unwrap());
let datetime = DateTime::<Utc>::from(d);
let timestamp_str = datetime.format("%Y-%m-%d %H:%M:%S").to_string();
if i.data.title != None {
println!(
"{} {}",
"title".green(),
i.data
.title
.unwrap_or_else(|| "unknown".to_string())
.magenta()
2022-01-23 12:05:32 +00:00
);
}
if i.data.description != None {
println!(
"{} {}",
"description".green(),
i.data
.description
.unwrap_or_else(|| "unknown".to_string())
.magenta()
2022-01-23 12:05:32 +00:00
);
}
if i.data.deletehash != None {
println!(
"{} {}",
"deletehash".green(),
i.data
.deletehash
.unwrap_or_else(|| "unknown".to_string())
.magenta()
2022-01-23 12:05:32 +00:00
);
}
println!("{} {}", "id".green(), i.data.id.magenta());
println!(
"{} {} {}",
"upload date".green(),
timestamp_str.magenta(),
"(UTC)".blue()
);
println!("{} {}", "type".green(), i.data.img_type.magenta());
println!("{} {}", "width".green(), i.data.width.to_string().magenta());
println!(
"{} {}",
"height".green(),
i.data.height.to_string().magenta()
);
println!(
"{} {} {}",
"size".green(),
(i.data.size / 1000).to_string().magenta(),
"KB".blue()
);
println!("{} {}", "views".green(), i.data.views.to_string().magenta());
println!(
"{} {}",
"bandwidth".green(),
i.data.bandwidth.to_string().magenta()
);
println!("{} {}", "link".green(), i.data.link.magenta());
2022-01-23 12:05:32 +00:00
}