Added metadata
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "i3status-custom-pim"
|
name = "i3status-custom-pim"
|
||||||
|
description = "Generates JSON output for use with custom block of i3status-rust."
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Martin Bley <martin@mb-oss.de>"]
|
authors = ["Martin Bley <martin@mb-oss.de>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
@@ -7,4 +8,5 @@ edition = "2018"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
structopt = "0.3"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
|
|||||||
74
src/main.rs
74
src/main.rs
@@ -1,67 +1,21 @@
|
|||||||
use chrono::{Local, NaiveTime};
|
use structopt::StructOpt;
|
||||||
use std::process::Command;
|
|
||||||
|
#[derive(Debug, StructOpt)]
|
||||||
|
#[structopt( author, about)]
|
||||||
|
struct Cli {
|
||||||
|
#[structopt(short = "k", help="output khal events")]
|
||||||
|
khal: bool,
|
||||||
|
#[structopt(short = "t", help="output todos")]
|
||||||
|
todo: bool,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
const THRESHOLD_WARNING: i64 = 60;
|
let args = Cli::from_args();
|
||||||
const THRESHOLD_CRITICAL: i64 = 15;
|
|
||||||
let icon = String::from("calendar");
|
|
||||||
|
|
||||||
let mut events: Vec<String> = Vec::new();
|
if args.khal && args.todo {
|
||||||
let now = Local::now().time();
|
println!("khal");
|
||||||
let from = now.format("%H:%M").to_string();
|
|
||||||
|
|
||||||
let khal_cmd = Command::new("khal")
|
|
||||||
.arg("list")
|
|
||||||
.arg("-df")
|
|
||||||
.arg("{name}")
|
|
||||||
.arg("-f")
|
|
||||||
.arg("{start-time}")
|
|
||||||
.arg("--notstarted")
|
|
||||||
.arg(&from)
|
|
||||||
.arg("23:59")
|
|
||||||
.output();
|
|
||||||
|
|
||||||
let khal_output = khal_cmd.expect("failed to run command");
|
|
||||||
let khal_stdout = String::from_utf8(khal_output.stdout)
|
|
||||||
.expect("can't read output");
|
|
||||||
|
|
||||||
let mut lines = khal_stdout.lines();
|
|
||||||
let dayline = lines.nth(0).expect("output seems empty");
|
|
||||||
|
|
||||||
if dayline.trim() == "Today" {
|
|
||||||
for e in lines {
|
|
||||||
events.push(e.to_string());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get duration up to next event and set state
|
println!("{:?}", args);
|
||||||
let mut state = String::from("Idle");
|
|
||||||
|
|
||||||
let mut event_remaining: i64 = 24 * 60;
|
|
||||||
let event_count = events.len();
|
|
||||||
for e in events.iter() {
|
|
||||||
let e_start = match NaiveTime::parse_from_str(e, "%H:%M") {
|
|
||||||
Ok(s) => s,
|
|
||||||
Err(_f) => NaiveTime::from_hms(0, 0, 0),
|
|
||||||
};
|
|
||||||
let diff = e_start - now;
|
|
||||||
if (diff.num_minutes() < event_remaining) &&
|
|
||||||
(diff.num_minutes() >= 0) {
|
|
||||||
event_remaining = diff.num_minutes()
|
|
||||||
}
|
|
||||||
|
|
||||||
if event_remaining >= 0 {
|
|
||||||
if event_remaining <= THRESHOLD_WARNING {
|
|
||||||
state = String::from("Warning");
|
|
||||||
}
|
|
||||||
if event_remaining <= THRESHOLD_CRITICAL {
|
|
||||||
state = String::from("Critical");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"{{ \"icon\": \"{}\", \"state\": \"{}\", \"text\": \"{}\" }}",
|
|
||||||
icon, state, event_count
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user