start with notes program

This commit is contained in:
2026-01-22 21:02:28 +01:00
parent a699022812
commit 1967a3e1d6
4 changed files with 292 additions and 16 deletions

155
autotodo/Cargo.lock generated
View File

@@ -11,6 +11,56 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
[[package]]
name = "anstyle-parse"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
]
[[package]]
name = "autocfg"
version = "1.5.0"
@@ -22,6 +72,8 @@ name = "autotodo"
version = "0.1.0"
dependencies = [
"chrono",
"clap",
"env",
"ron",
"serde",
]
@@ -71,18 +123,79 @@ dependencies = [
"windows-link",
]
[[package]]
name = "clap"
version = "4.5.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32"
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "env"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc95de49ad098572c02d3fbf368c9a020bfff5ae78483685b77f51d8a7e9486d"
dependencies = [
"num_threads",
]
[[package]]
name = "find-msvc-tools"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "iana-time-zone"
version = "0.1.64"
@@ -107,6 +220,12 @@ dependencies = [
"cc",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "js-sys"
version = "0.3.85"
@@ -138,12 +257,27 @@ dependencies = [
"autocfg",
]
[[package]]
name = "num_threads"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9"
dependencies = [
"libc",
]
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "proc-macro2"
version = "1.0.106"
@@ -218,6 +352,12 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.114"
@@ -241,6 +381,12 @@ version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "wasm-bindgen"
version = "0.2.108"
@@ -344,3 +490,12 @@ checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]

View File

@@ -5,5 +5,7 @@ edition = "2024"
[dependencies]
chrono = { version = "0.4.43", features = ["serde"] }
clap = { version = "4.5.54", features = ["derive"] }
env = "1.0.1"
ron = "0.12.0"
serde = { version = "1.0.228", features = ["derive"] }

32
autotodo/data/notes.md Normal file
View File

@@ -0,0 +1,32 @@
i: into issue
d: someone else did it / took "assignment" (spiritual or actually in Gitea)
r: tried unsucessfully, have to retry
m: moved to a later, specified time
c: i will come back to this when i feel like it, but no need to track it now
p: Made progress, but not done
n: no (catchall for not doing it)
# 2026-01-20
- [ ] Test 1
- [ ] Test 2
- [x] Test 3
- [ ] Test 4
- [ ] Test 5
# 2026-01-21
- [x] Test 1
- [ ] Test 2
- [ ] Test 6
- [ ] Test 7
# 2026-01-22
- [ ] Test 1
- [ ] Test 2
- [ ] Test 4
- [ ] Test 5
- [ ] Test 6
- [ ] Test 7

View File

@@ -1,33 +1,120 @@
use std::fs;
use ron;
use serde::{Serialize, Deserialize};
use chrono;
use chrono::{self, NaiveDate, Local};
use clap::Parser;
use serde::{Deserialize, Serialize};
use std::{
collections::HashSet, fmt::Write as _, fs::{File, OpenOptions}, io::{BufRead, BufReader, Read, Seek, Write as _}, path::{Path, PathBuf}
};
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
notes: PathBuf,
patterns: Option<PathBuf>,
}
#[derive(Serialize, Deserialize, Debug)]
enum Pattern {
Yearly { doy: u32 },
MonthlyOpt { dom: u32, months: Vec<chrono::Month> },
Monthly { dom: u32 },
Weekly { dow: u32 },
Yearly {
doy: u32,
},
MonthlyOpt {
dom: u32,
months: Vec<chrono::Month>,
},
Monthly {
dom: u32,
},
Weekly {
dow: u32,
},
Daily,
}
#[derive(Serialize, Deserialize, Debug)]
struct Position {
name: String,
pattern: Pattern
pattern: Pattern,
}
fn parse_patterns() {
let f = fs::read_to_string("data/patterns.ron").expect("file should exist");
let patterns: Vec<Position> = ron::from_str(&f).expect("file should follow proper ron syntax");
dbg!(patterns);
}
fn update_notes(notes_path: &Path) {
let mut file = OpenOptions::new().read(true).write(true).open(notes_path).expect("file should exist");
let mut bufreader = BufReader::new(&file);
let mut linebuf = String::new();
let mut all_lines = String::new();
let mut latest_date = NaiveDate::MIN;
let mut lines_with_duplicates: Vec<usize> = Vec::new();
// Find todo-type lines
while let Ok(n) = bufreader.read_line(&mut linebuf) {
if n == 0 {
break;
}
let trimmed_str = linebuf.trim();
let trimmed_bytes = trimmed_str.as_bytes();
let Some(sub) = trimmed_bytes.get(0..5) else { continue; };
println!("cur line is {:?}. Sub is {:?}", trimmed_str, sub);
if sub == b"- [ ]" {
all_lines.push_str(&linebuf);
} else if trimmed_bytes.get(0) == Some(&b'#') {
if let Ok(date) = NaiveDate::parse_from_str(trimmed_str.get(1..).unwrap(), "%Y-%m-%d") {
if date > latest_date {
latest_date = date;
}
}
}
linebuf.clear();
}
// Find duplicates
let mut todos_hashset: HashSet<&str> = HashSet::new();
for (idx, line) in all_lines.split("\n").enumerate() {
if !todos_hashset.insert(line) {
lines_with_duplicates.push(idx);
}
}
// Prepare buffer
let res1 = bufreader.seek(std::io::SeekFrom::End(-2));
let mut last_two_bytes = [0u8, 0u8];
let res2 = bufreader.read_exact(&mut last_two_bytes);
if last_two_bytes != *b"\n\n" {
write!(linebuf, "\n");
}
let today = Local::now().date_naive();
if latest_date < today {
writeln!(linebuf, "# {}", today);
}
fn parse_notes() {
let mut cur = 0;
for (idx, line) in all_lines.split("\n").enumerate() {
if cur < lines_with_duplicates.len() && lines_with_duplicates[cur] == idx {
cur += 1;
} else {
writeln!(linebuf, "{line}");
}
}
println!("{:?}", file.write_all(linebuf.as_bytes()));
// TODO: Handle case if today already exists
// TODO: Dont put once-open but now closed todos in
// Opt: Create new date for today
// Put all open todos into today
}
fn parse_patterns(notes_path: &Path, patterns_path: &Path) {
// Put all patternized todos into today
}
fn main() {
parse_patterns();
let args = Args::parse();
update_notes(&args.notes);
if let Some(patterns_path) = args.patterns {
parse_patterns(&args.notes, &patterns_path);
}
}