Added metadata

This commit is contained in:
2020-11-18 21:42:54 +01:00
parent 314c2fa7b1
commit f6dc45e7d2
2 changed files with 16 additions and 60 deletions

View File

@@ -1,5 +1,6 @@
[package]
name = "i3status-custom-pim"
description = "Generates JSON output for use with custom block of i3status-rust."
version = "0.1.0"
authors = ["Martin Bley <martin@mb-oss.de>"]
edition = "2018"
@@ -7,4 +8,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
structopt = "0.3"
chrono = "0.4"

View File

@@ -1,67 +1,21 @@
use chrono::{Local, NaiveTime};
use std::process::Command;
use structopt::StructOpt;
#[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() {
const THRESHOLD_WARNING: i64 = 60;
const THRESHOLD_CRITICAL: i64 = 15;
let icon = String::from("calendar");
let args = Cli::from_args();
let mut events: Vec<String> = Vec::new();
let now = Local::now().time();
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());
}
if args.khal && args.todo {
println!("khal");
}
// get duration up to next event and set state
let mut state = String::from("Idle");
println!("{:?}", args);
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
);
}