imgurs/src/cli/mod.rs

66 lines
1.8 KiB
Rust
Raw Normal View History

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;
2022-01-23 12:05:32 +00:00
use crate::config::toml::parse;
use imgurs::api::ImageInfo;
2022-01-25 16:13:43 +00:00
use chrono::{prelude::DateTime, Utc};
2022-01-24 19:40:08 +00:00
use log::{error, info};
use notify_rust::Notification;
2022-01-25 16:14:23 +00:00
use std::{
process::exit,
time::{Duration, UNIX_EPOCH},
};
2022-01-23 12:05:32 +00:00
pub fn print_image_info(i: ImageInfo, notify: bool) {
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 {
info!(
"Title {}",
2022-01-23 13:33:24 +00:00
i.data.title.unwrap_or_else(|| "unknown".to_string())
2022-01-23 12:05:32 +00:00
);
}
if i.data.description != None {
info!(
"Description {}",
2022-01-23 13:33:24 +00:00
i.data.description.unwrap_or_else(|| "unknown".to_string())
2022-01-23 12:05:32 +00:00
);
}
if i.data.deletehash != None {
info!(
"Deletehash {}",
2022-01-23 13:33:24 +00:00
i.data.deletehash.unwrap_or_else(|| "unknown".to_string())
2022-01-23 12:05:32 +00:00
);
}
info!("ID {}", i.data.id);
info!("Upload Date {} (UTC)", timestamp_str);
info!("Type {}", i.data.img_type);
info!("Width {}", i.data.width);
info!("Height {}", i.data.height);
info!("File Size {} KB", i.data.size / 1000);
info!("Views {}", i.data.views);
info!("Bandwidth {}", i.data.bandwidth);
info!("Link {}", i.data.link);
2022-01-24 22:15:55 +00:00
let config = parse();
2022-01-24 22:15:55 +00:00
if notify && config.notification.enabled {
Notification::new()
.summary("Imgurs")
.body(&format!("Uploaded {}", i.data.link))
2022-01-24 19:40:08 +00:00
.show()
.unwrap_or_else(|e| {
error!("send notification: {}", e);
exit(2)
});
}
2022-01-23 12:05:32 +00:00
}