Compare commits
2 Commits
79596f3ae5
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb87ec572c | ||
|
|
c5e1713ef4 |
75
Cargo.lock
generated
75
Cargo.lock
generated
@@ -154,12 +154,24 @@ version = "0.8.7"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "equivalent"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "find-msvc-tools"
|
name = "find-msvc-tools"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d"
|
checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.15.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -190,12 +202,28 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indexmap"
|
||||||
|
version = "2.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "206a8042aec68fa4a62e8d3f7aa4ceb508177d9324faf261e1959e495b7a1921"
|
||||||
|
dependencies = [
|
||||||
|
"equivalent",
|
||||||
|
"hashbrown",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "is_terminal_polyfill"
|
name = "is_terminal_polyfill"
|
||||||
version = "1.70.1"
|
version = "1.70.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.78"
|
version = "0.3.78"
|
||||||
@@ -263,6 +291,45 @@ version = "1.0.22"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.219"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.219"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_yaml"
|
||||||
|
version = "0.9.34+deprecated"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
"unsafe-libyaml",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
@@ -292,6 +359,12 @@ version = "1.0.18"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unsafe-libyaml"
|
||||||
|
version = "0.2.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8parse"
|
name = "utf8parse"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
@@ -304,6 +377,8 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
"serde",
|
||||||
|
"serde_yaml",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.47", features = ["derive"] }
|
clap = { version = "4.5.47", features = ["derive"] }
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
|
serde_yaml = "0.9.34"
|
||||||
|
serde = {version = "1.0.219", features = ["derive"] }
|
||||||
|
|||||||
21
src/main.rs
21
src/main.rs
@@ -92,8 +92,9 @@ fn read_daily_post_metadata(filepath: &str)-> Result<DailyPostMetadata, &str> {
|
|||||||
|
|
||||||
fn update_streak(daily_filepath: &str, file: &mut File) {
|
fn update_streak(daily_filepath: &str, file: &mut File) {
|
||||||
// Get filepath from yesterday. If does not exist, return 0.
|
// Get filepath from yesterday. If does not exist, return 0.
|
||||||
let mut streak: u32 = 0;
|
let streak: u32 = 0;
|
||||||
let yesterday_filepath = get_yesterday_filepath();
|
let yesterday_filepath = get_yesterday_filepath();
|
||||||
|
let today = Local::now();
|
||||||
|
|
||||||
if let Err(e) = yesterday_filepath {
|
if let Err(e) = yesterday_filepath {
|
||||||
let today_metadata = DailyPostMetadata {
|
let today_metadata = DailyPostMetadata {
|
||||||
@@ -101,12 +102,15 @@ fn update_streak(daily_filepath: &str, file: &mut File) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
||||||
file.write_all(stringified_yaml.as_bytes()).expect("Unable to write YAML metadata");
|
let yaml = format!("---\n{}\n---\n", &stringified_yaml);
|
||||||
|
file.write_all(yaml.as_bytes()).expect("Unable to write YAML metadata");
|
||||||
|
|
||||||
return ();
|
return ();
|
||||||
}
|
}
|
||||||
|
|
||||||
let filepath = yesterday_filepath.unwrap();
|
let filename = yesterday_filepath.unwrap();
|
||||||
let metadata: Result<DailyPostMetadata, &str> = read_daily_post_metadata(&filepath);
|
let fp = format!("{}/{}/{}", &daily_filepath, today.year(), filename);
|
||||||
|
let metadata: Result<DailyPostMetadata, &str> = read_daily_post_metadata(&fp);
|
||||||
|
|
||||||
// Get metadata from yesterday's post. If metadata does not exist, return 1.
|
// Get metadata from yesterday's post. If metadata does not exist, return 1.
|
||||||
if let Err(e) = metadata {
|
if let Err(e) = metadata {
|
||||||
@@ -115,7 +119,8 @@ fn update_streak(daily_filepath: &str, file: &mut File) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
||||||
file.write_all(stringified_yaml.as_bytes()).expect("Unable to write YAML metadata");
|
let yaml = format!("---\n{}\n---\n", &stringified_yaml);
|
||||||
|
file.write_all(yaml.as_bytes()).expect("Unable to write YAML metadata");
|
||||||
return ();
|
return ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,9 +128,11 @@ fn update_streak(daily_filepath: &str, file: &mut File) {
|
|||||||
let today_metadata = DailyPostMetadata {
|
let today_metadata = DailyPostMetadata {
|
||||||
streak: prev_metadata.streak + 1,
|
streak: prev_metadata.streak + 1,
|
||||||
};
|
};
|
||||||
|
println!("two");
|
||||||
|
|
||||||
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
let stringified_yaml = serde_yaml::to_string(&today_metadata).unwrap();
|
||||||
file.write_all(stringified_yaml.as_bytes()).expect("Unable to write YAML metadata");
|
let yaml = format!("---\n{}\n---\n", &stringified_yaml);
|
||||||
|
file.write_all(yaml.as_bytes()).expect("Unable to write YAML metadata");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -144,6 +151,7 @@ fn main() {
|
|||||||
let file_exists = directory_iterator.any(|filename| *filename.unwrap().file_name() == *file_name);
|
let file_exists = directory_iterator.any(|filename| *filename.unwrap().file_name() == *file_name);
|
||||||
|
|
||||||
if !file_exists {
|
if !file_exists {
|
||||||
|
println!("file does not exist");
|
||||||
// Create a new file
|
// Create a new file
|
||||||
let mut file = File::create(&file_path).unwrap();
|
let mut file = File::create(&file_path).unwrap();
|
||||||
|
|
||||||
@@ -153,6 +161,7 @@ fn main() {
|
|||||||
// Write date at the start
|
// Write date at the start
|
||||||
let date_header = format!("# {}", &today_date_str);
|
let date_header = format!("# {}", &today_date_str);
|
||||||
writeln!(&mut file, "{}", &date_header);
|
writeln!(&mut file, "{}", &date_header);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user