Compare commits

...

13 commits
v1.1.0 ... main

Author SHA1 Message Date
Campbell Alden
ecd732dbbd Update the readme since v2 broke a lot of options 2024-12-27 09:48:28 +09:00
Campbell Alden
fb711c2810 Update the day reporter to support more arbitrary reporting from things lists and between arbitrary dates 2024-12-24 12:28:07 +09:00
Campbell Alden
9d62d4d555 Update the day reporter to use lists instead of report types 2024-12-24 11:58:22 +09:00
Campbell Alden
154793ccbe Speedup the signoff report by short circuiting when the first task not on today is found 2024-12-23 18:09:41 +09:00
Campbell Alden
c6942468b2 Allow filtering reported tasks such that certain tags are omitted 2024-05-08 11:00:26 +09:00
Campbell Alden
29d1d5a2ef Handle canceled tasks 2024-03-13 18:17:50 +09:00
Campbell Alden
f1ac5bb718 BUG FIX: Report relevant notes after a project title when there are notes on a project 2024-02-28 09:24:54 +09:00
Campbell Alden
52b869cca5 Sort tasks by completion date (newer later) 2024-01-10 10:23:26 +09:00
Campbell Alden
9fa5818fde Remove redundant clone() 2024-01-10 10:23:09 +09:00
Campbell Alden
23eaf0c5d8 Add new emojis 2023-08-04 10:43:23 +09:00
Campbell Alden
a9658a9d94 v1.2.1 2023-07-24 22:50:04 +09:00
Campbell Alden
30b22de2b9 Improve CLI arguments and help text 2023-07-24 22:45:08 +09:00
Campbell Alden
b7cedea8eb Update README 2023-07-24 14:44:25 +09:00
9 changed files with 189 additions and 184 deletions

2
Cargo.lock generated
View file

@ -173,7 +173,7 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "day-reporter"
version = "1.1.0"
version = "2.0.0"
dependencies = [
"anyhow",
"chrono",

View file

@ -1,6 +1,6 @@
[package]
name = "day-reporter"
version = "1.1.0"
version = "2.0.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,41 +1,38 @@
# things-3-report
A small script to generate bulleted reports from my Things 3 tasks
A small program written in rust that digests my Things tasks into a format for Slack reporting.
## Usage
The environment should be provided by `nix-shell`. Alternatively you can install the requirements directly with
```bash
$ pip install -r requirements.txt
Tasks are pulled out of Things using AppleScript over a JavaScript OSA Bridge. Tasks are then filtered
and formatted based on the selected format schema.
## Options
See `day-reporter -h` for a current list of options
## Basic Task format
A task is returned as a markdown list element containing its title and optionally a list of information parsed from
related tag sections in the notes portion of the task.
Tag specific additional bullets are included using a triple backtick (like GitHub code block markdown). Then instead of
specifying the coding style as you would (for example `typescript`) you specify the relevant tag: `MyTag`. Running the
program with a given `--tags` argument will cause related tag blocks to be included as sub-bullets.
### Example
<pre>
```MyTag
Some notes
```
To run the script, pass in the tag or list of tags to filter on. Projects and Tasks lacking one of the specified tags will be excluded from the generated report. I have a `Report` tag which I use for this. If a project is tagged with the tag, all tasks are considered tagged even if not explicitly done so.
</pre>
### Specific functionality
I have also included a few pieces of additional functionality:
- The project is headed with a set of 3 randomly selected emojis from `emojis.txt`
- If you have a person's name in the task or project title, you can add an `@<Persons Name>` tag to the task or project and the script will automatically replace the vowels in their name with unicode that looks similar. This allows you to post the list on slack without generating mentions.
- Adding a code block that begins with `report` will cause the script to dump the contents into the end of the generated message. This can be used to add notes to the generated output.
- Be default the script draws from today's current list of tasks. If you specify `--signoff` it will instead draw on completed tasks from your logbook. (This is useful for an end of the day message).
will result in "Some notes" being included with the task
## Example Usage:
Given a set of tasks tagged `Report`
```txt
Project named "Some Project" tagged as Report:
containing two tasks (not necessarily tagged) "Task 1" and "Task 2"
## Name Sanitization
Name tags found on projects and tasks are automatically sanitized by replacing vowel characters with lookalikes. This
behavior can be disabled with the `--no-sanitize` argument.
A top level task called some task with a notes filed containing
```report
(#9999)[https://example.com]
`` ` <-- No space there but it's hard to escape these ticks
```
## Project Formatting
Projects make up a bullet level above tasks. Any tasks in the project will be nested under the project title following
and project specific matched tag block comments in the project notes.
```
$ python dump.py Report
```
will generate:
```txt
:emoji: :emoji: :emoji:
- Some Project
- Task 1
- Task 2
- Some Task (#9999)(https://example.com)
```
## Area Formatting
Areas collect up projects, but instead of indenting them further, Area's are returned as section titles above the
generated output. If only one area contains all of the reported tasks, then the area name is omitted entirely.

View file

@ -1,15 +1,22 @@
:audioowl:
:ayaya:
:blobcat_cookie:
:blobcat_munch:
:boat-cat:
:bouquet_owl:
:cat-confused:
:cat-cook:
:cat-dance:
:cat-on-the-laptop:
:cat-peek:
:cat-roll:
:cat-roomba-exceptionally-fast:
:cat-roomba:
:cat-shook:
:cat-skype:
:cat_blush:
:cat_bobble:
:cat_clap:
:cat_type:
:catcat:
:catdance:
@ -31,22 +38,27 @@
:dancing_dog:
:deadowl:
:dnowl:
:dog_cool:
:doge-dance-kfc:
:doge:
:dogjam:
:eikaiwaowl:
:eve-owl:
:eve-owl-evil:
:eve-owl:
:fakeowl:
:french-bulldog_massage:
:gatocat:
:grumpycat:
:gull_scream:
:heart-eyes-dog:
:hungry_cat:
:i_regret_nothing:
:insomnia-owl:
:investigate-owl:
:jakethedog1:
:jakethedog2:
:jenkinsowl:
:long_cat:
:look-owl:
:loopyowl:
:love_letter_owl:
@ -67,8 +79,8 @@
:meow_buzz:
:meow_camera:
:meow_code:
:meow_coffee:
:meow_coffee2:
:meow_coffee:
:meow_comfy:
:meow_comfy_coffee:
:meow_comfydonut:
@ -126,9 +138,12 @@
:meowth:
:mild-surprise-owl:
:nerd-cat:
:nerdcat:
:octocat1:
:octocat2:
:octocat3:
:ok-owl:
:omg-owl:
:owl-travel:
:owl_celebration:
:owl_christmas_stocking:
@ -149,7 +164,9 @@
:realowl_back:
:realowl_guruguru:
:realowl_side:
:rodger-owl:
:sakura_owl:
:seems-good-owl:
:shrodingers-cat:
:steampunk-owl:
:stopowl:

View file

@ -5,95 +5,112 @@ mod names;
use reporter::{MarkdownReporter, Reporter, Resolution, ReportOptions};
use things::task::{Task, Status};
use things::task::Task;
use anyhow::Result;
use clap::{Parser, ValueEnum};
#[derive(ValueEnum, Copy, Clone, Eq, PartialEq)]
enum Modes {
/// Generate a report containing projected work for the day and a morning message
Morning,
/// Generate a report that is intended to be used for sharing what major tasks were completed
/// in the last cycle.
Cycle,
/// Generate a report for what was actually done today and a signoff message
Signoff,
enum ListType {
/// Generate a report from the Things today list
Today,
/// Generate a report from the Things logbook
Logbook,
}
impl Modes {
fn format_tasks(&self, tasks: Vec<Task>, tags: &Vec<String>, sanitize_names: bool) -> String {
impl ListType {
fn format_tasks(&self, tasks: Vec<Task>, tags: &Vec<String>, sanitize_names: bool, resolution: Resolution) -> String {
match self {
Modes::Morning => {
let task_report = MarkdownReporter.report(tasks, &ReportOptions {
resolution: Resolution::FullTask,
ListType::Today => {
MarkdownReporter.report(tasks, &ReportOptions {
resolution,
tags: tags.to_vec(),
sanitize_names,
});
format!("{}\n\n{}", emoji::pick(3).join(" "), task_report)
})
},
Modes::Signoff => {
let task_report = MarkdownReporter.report(tasks, &ReportOptions {
resolution: Resolution::FullTask,
ListType::Logbook => {
MarkdownReporter.report(tasks, &ReportOptions {
resolution,
tags: tags.to_vec(),
sanitize_names,
});
format!("Stopping now\n\n{}", task_report)
},
Modes::Cycle => {
let further_filtered = tasks.into_iter().filter(|t| {
if let Some(p) = &t.project {
return p.status == Status::Completed;
}
return false;
}).collect::<Vec<Task>>();
let task_report = MarkdownReporter.report(further_filtered, &ReportOptions {
resolution: Resolution::Project,
tags: tags.to_vec(),
sanitize_names,
});
format!("*Cycle Report*\n\n{}", task_report)
})
},
}
}
}
impl Default for Modes {
fn default() -> Modes {
Modes::Morning
impl Default for ListType {
fn default() -> ListType {
ListType::Today
}
}
/// A program that generates Slack flavor markdown reports from Things 3 todo list items.
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct CliArgs {
/// A list of tags to filter requests on
/// A list of tags to filter todos by. Only todo list items with every tag will be reported
#[arg(short, long)]
tags: Vec<String>,
/// Control what type of report to generate
#[arg(short, long, default_value_t = Modes::default())]
/// A list of tags to specifically omit from the results. Only todo list items WITHOUT these
/// tags will be included
#[arg(short, long)]
omit: Vec<String>,
/// Select the type of report to generate
#[arg(short, long, default_value_t = ListType::default())]
#[clap(value_enum)]
mode: Modes,
list: ListType,
/// By default, any @<name> style tags will be sanitized in the output to avoid @-mentions in
/// slack. This is done by replacing vowel characters with look unicode lookalikes. If this
/// flag is set then the names will be passed through unsanitized
/// Slack. This is done by replacing vowel characters with unicode lookalikes. If this
/// flag is set then the names will be passed through unsanitized.
#[arg(long, default_value_t = false)]
no_sanitize: bool,
/// An ISO date string for when to filter tasks from.
/// Defaults to midnight this morning if unset. Not used for the today list
#[arg(long)]
from: Option<String>,
/// An ISO date string for when to filter tasks until.
/// Defaults to 1 second before midnight tonight if unset. Not used for the today list
#[arg(long)]
to: Option<String>,
/// An optional message to include at the beginning of the report. If omitted, 3 random emojis
/// will be included instead
#[arg(short, long)]
message: Option<String>,
/// Choose a resolution for the report. This will determine how much detail is included in the
/// output. Default is "FullTask"
#[arg(short, long, default_value_t = Resolution::default())]
#[clap(value_enum)]
resolution: Resolution,
}
fn main() -> Result<()> {
let args = CliArgs::parse();
let tasks = match args.mode {
Modes::Morning => Task::today(),
Modes::Signoff => Task::logbook_today(),
Modes::Cycle => Task::logbook_this_cycle(),
let now = chrono::Local::now();
let from = args.from.unwrap_or_else(|| now.date().and_hms(0, 0, 0).to_rfc3339());
let to = args.to.unwrap_or_else(|| (now + chrono::Duration::days(1)).date().and_hms(0, 0, 0).to_rfc3339());
let message = args.message.unwrap_or_else(|| emoji::pick(3).join(" "));
let tasks = match args.list {
ListType::Today => Task::today(&from, &to),
ListType::Logbook => Task::logbook(&from, &to),
}?;
let reported: Vec<Task> = tasks.into_iter().filter(|task| {
args.tags.iter().all(|tag| task.has_tag(tag))
let mut reported: Vec<Task> = tasks.into_iter().filter(|task| {
// Filter down to tasks with all selected tags and without any of the omitted tags
args.tags.iter().all(|tag| task.has_tag(tag)) && !args.omit.iter().any(|tag| task.has_tag(tag))
}).collect();
let report = args.mode.format_tasks(reported, &args.tags, !args.no_sanitize);
println!("{report}");
reported.sort_by(|a, b| {
a.completion_date.cmp(&b.completion_date)
});
let report = args.list.format_tasks(reported, &args.tags, !args.no_sanitize, args.resolution);
println!("{message}\n\n{report}");
Ok(())
}

View file

@ -1,4 +1,6 @@
use crate::things::task::Task;
use clap::ValueEnum;
use crate::things::task::{Task, Status};
use crate::names::sanitize_names;
/// Given a notes field and a list of possible tags for sections, return the content of triple tick
@ -59,8 +61,8 @@ pub struct ThingsTree {
impl AreaTree {
fn new(id: &str, title: &str) -> AreaTree {
AreaTree {
id: id.clone().to_string(),
title: title.clone().to_string(),
id: id.to_string(),
title: title.to_string(),
projects: vec![],
hanging_tasks: vec![],
}
@ -126,11 +128,18 @@ impl ThingsTree {
}
}
#[derive(ValueEnum, Copy, Clone, Eq, PartialEq)]
pub enum Resolution {
FullTask,
Project,
}
impl Default for Resolution {
fn default() -> Resolution {
Resolution::FullTask
}
}
pub struct ReportOptions {
pub resolution: Resolution,
pub tags: Vec<String>,
@ -176,11 +185,17 @@ impl Reporter for MarkdownReporter {
.map(|l| format!("\n{}- {}", String::from(" ").repeat(depth + 4), l))
.collect::<Vec<String>>()
.join("");
let mut output = format!("\n{}- {}{}", String::from(" ").repeat(depth), task.title, relevant_notes);
let title = if task.status == Status::Canceled {
format!("~{}~", task.title)
} else {
task.title.to_string()
};
let mut output = format!("\n{}- {}{}", String::from(" ").repeat(depth), title, relevant_notes);
if options.sanitize_names {
output = sanitize_names(&output, &task.tags);
}
return output;
output
}
fn report_project(&mut self, project: &ProjectTree, depth: usize, options: &ReportOptions) -> String {
let resolution = &options.resolution;
@ -198,7 +213,7 @@ impl Reporter for MarkdownReporter {
.map(|t| self.report_task(t, depth + 4, options))
.collect::<Vec<String>>()
.join("");
format!("{}{}{}{}", String::from(" ").repeat(depth), relevant_notes, project.title, tasks)
format!("{}{}{}{}", String::from(" ").repeat(depth), project.title, relevant_notes, tasks)
},
Resolution::Project => {
format!("{}- {}{}", String::from(" ").repeat(depth), project.title, relevant_notes)
@ -209,7 +224,7 @@ impl Reporter for MarkdownReporter {
output = sanitize_names(&output, &project.tags);
}
return output;
output
}
fn report_single_area(&mut self, area: &AreaTree, options: &ReportOptions) -> String {
let project_reports = area.projects

View file

@ -2,41 +2,36 @@ var things = Application("Things");
var logbook = things.lists.byName("Logbook").toDos();
var objs = [];
var from = new Date();
from.setHours(0);
from.setMinutes(0);
from.setSeconds(0);
var to = new Date();
to.setTime(from.getTime());
to.setHours(23);
to.setMinutes(59);
to.setSeconds(59);
var from = new Date($params.from);
var to = new Date($params.to);
logbook.filter(task => {
return task.completionDate() >= from && task.completionDate() < to;
}).forEach(todo => {
var proj = todo.project();
var tags = [];
if (proj) {
tags.push(...proj.tagNames().split(', '));
for (const todo of logbook) {
if(todo.completionDate() >= from && todo.completionDate() < to) {
var proj = todo.project();
var tags = [];
if (proj) {
tags.push(...proj.tagNames().split(', '));
}
var area = todo.area() || proj && proj.area();
objs.push({
id: todo.id(),
title: todo.name(),
notes: todo.notes() || null,
status: todo.status(),
completion_date: todo.completionDate(),
project: proj && {
id: proj.id(),
title: proj.name(),
status: proj.status(),
notes: proj.notes(),
tags: proj.tagNames().split(', '),
},
area: area && { id: area.id(), title: area.name() },
tags: [...tags, ...todo.tagNames().split(', ')].filter(t => t),
});
} else {
break;
}
var area = todo.area() || proj && proj.area();
objs.push({
id: todo.id(),
title: todo.name(),
notes: todo.notes() || null,
status: todo.status(),
completion_date: todo.completionDate(),
project: proj && {
id: proj.id(),
title: proj.name(),
status: proj.status(),
notes: proj.notes(),
tags: proj.tagNames().split(', '),
},
area: area && { id: area.id(), title: area.name() },
tags: [...tags, ...todo.tagNames().split(', ')].filter(t => t),
});
});
}
return JSON.stringify(objs, undefined, 2);

View file

@ -1,42 +0,0 @@
var things = Application("Things");
var logbook = things.lists.byName("Logbook").toDos();
var objs = [];
// From 6 weeks ago
var from = new Date(new Date().getTime() - (6 * 7 * 24 * 60 * 60 * 1000));
from.setHours(0);
from.setMinutes(0);
from.setSeconds(0);
var to = new Date();
to.setHours(23);
to.setMinutes(59);
to.setSeconds(59);
logbook.filter(task => {
return task.completionDate() >= from && task.completionDate() < to;
}).forEach(todo => {
var proj = todo.project();
var tags = [];
if (proj) {
tags.push(...proj.tagNames().split(', '));
}
var area = todo.area() || proj && proj.area();
objs.push({
id: todo.id(),
title: todo.name(),
notes: todo.notes() || null,
status: todo.status(),
completion_date: todo.completionDate(),
project: proj && {
id: proj.id(),
title: proj.name(),
status: proj.status(),
notes: proj.notes(),
tags: proj.tagNames().split(', '),
},
area: area && { id: area.id(), title: area.name() },
tags: [...tags, ...todo.tagNames().split(', ')].filter(t => t),
});
});
return JSON.stringify(objs, undefined, 2);

View file

@ -1,5 +1,5 @@
use std::str::from_utf8;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use anyhow::Result;
use osascript;
use serde_json;
@ -13,6 +13,8 @@ pub enum Status {
Incomplete,
#[serde(rename = "open")]
Open,
#[serde(rename = "canceled")]
Canceled,
}
#[derive(Deserialize, Debug)]
@ -42,27 +44,31 @@ pub struct Task {
pub area: Option<Area>,
}
#[derive(Serialize, Debug)]
pub struct TaskParams {
// ISO string for the start date
from: String,
// ISO string for the end date
to: String,
}
impl Task {
/// A Helper for loading Tasks from json returned by an osascript
fn from_script(script_bytes: &[u8]) -> Result<Vec<Task>> {
fn from_script(script_bytes: &[u8], params: TaskParams) -> Result<Vec<Task>> {
let script = osascript::JavaScript::new(from_utf8(script_bytes)?);
let raw_json: String = script.execute()?;
let raw_json: String = script.execute_with_params(params)?;
let tasks: Vec<Task> = serde_json::from_str(&raw_json)?;
Ok(tasks)
}
/// Get all tasks in the today list from Things
pub fn today() -> Result<Vec<Task>> {
Task::from_script(include_bytes!("today.js"))
pub fn today(from: &String, to: &String) -> Result<Vec<Task>> {
Task::from_script(include_bytes!("today.js"), TaskParams { from: from.to_string(), to: to.to_string() })
}
/// Get all tasks in the logbook list from Things
pub fn logbook_today() -> Result<Vec<Task>> {
Task::from_script(include_bytes!("logbook.js"))
}
pub fn logbook_this_cycle() -> Result<Vec<Task>> {
Task::from_script(include_bytes!("logbook_cycle.js"))
pub fn logbook(from: &String, to: &String) -> Result<Vec<Task>> {
Task::from_script(include_bytes!("logbook.js"), TaskParams { from: from.to_string(), to: to.to_string() })
}
pub fn has_tag(&self, tag: &str) -> bool {