Specify input and output file paths

This commit is contained in:
clerie 2025-01-05 14:11:46 +01:00
parent 17b85d11b2
commit d86df2a44b
3 changed files with 140 additions and 3 deletions

120
Cargo.lock generated
View File

@ -41,6 +41,55 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
dependencies = [
"anstyle",
"windows-sys 0.59.0",
]
[[package]]
name = "anyhow"
version = "1.0.93"
@ -128,6 +177,52 @@ dependencies = [
"windows-targets",
]
[[package]]
name = "clap"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "core-foundation"
version = "0.9.4"
@ -325,6 +420,12 @@ version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "http"
version = "1.1.0"
@ -615,6 +716,12 @@ version = "2.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"
version = "1.0.14"
@ -838,6 +945,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"chrono",
"clap",
"feed-rs",
"reqwest",
]
@ -1119,6 +1227,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "subtle"
version = "2.6.1"
@ -1316,6 +1430,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uuid"
version = "1.11.0"

View File

@ -6,5 +6,6 @@ edition = "2021"
[dependencies]
anyhow = "1.0.93"
chrono = "0.4.38"
clap = { version = "4.5.23", features = ["derive"] }
feed-rs = "2.2.0"
reqwest = { version = "0.12.9", features = ["blocking"] }

View File

@ -2,6 +2,9 @@ use anyhow::{
Context,
Result,
};
use clap::{
Parser,
};
use feed_rs::{
parser::parse,
model::Feed,
@ -12,6 +15,17 @@ use reqwest::{
Url,
};
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
/// Path to file containing feeds
#[arg(long, default_value_t = String::from("feeds.txt"))]
feeds: String,
/// Path to output file
#[arg(long, default_value_t = String::from("index.html"))]
out: String,
}
fn fetch_feed(url: impl IntoUrl) -> Result<Feed> {
let content = reqwest::blocking::get(url)?.bytes()?;
Ok(parse(&content[..])?)
@ -38,10 +52,11 @@ fn read_feed_file(path: &str) -> Result<Vec<Url>> {
}
fn main() -> Result<()> {
let cli = Cli::parse();
let mut feed_items = Vec::new();
let feeds = read_feed_file("feeds.txt")?;
let feeds = read_feed_file(&cli.feeds)?;
for feed_url in feeds {
feed_items.extend(fetch_feed(feed_url)?.entries);
@ -60,7 +75,7 @@ fn main() -> Result<()> {
out.push_str("<ul>\n");
for item in feed_items {
out.push_str(&format!("<li><a href=\"{}\">{}</a> ({})</li>\n", item.links.first().context("No link found")?.href, item.title.context("No title found")?.content, item.published.context("")?));
out.push_str(&format!("<li><a href=\"{}\">{}</a> ({})</li>\n", item.links.first().context("No link found")?.href, item.title.context("No title found")?.content, item.published.context("No publishing time")?));
}
out.push_str("</ul>\n");
@ -68,7 +83,8 @@ fn main() -> Result<()> {
out.push_str("</body>\n");
out.push_str("</html>\n");
std::fs::write("index.html", out)?;
std::fs::write(&cli.out, out)
.context("Failed to write output to file")?;
Ok(())
}