summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs47
1 files changed, 36 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs
index ae68477..61701ab 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,10 +1,15 @@
+mod channel;
mod config;
mod retrieve;
+use std::future;
+
+use anyhow::anyhow;
use clap::Parser;
-use futures::executor::block_on;
+use futures::{StreamExt, executor::block_on};
+use rss::Channel;
-use crate::{config::Config, retrieve::retrieve};
+use crate::{channel::make_new_empty_channel, config::{ChannelConfig, Config}, retrieve::retrieve};
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
@@ -16,17 +21,37 @@ struct Args {
fn main() {
let args = Args::parse();
+ let config = load_config(&args.config_file).unwrap();
+ let channel = generate_channel(config.urls, config.channel);
+ write(&channel);
+}
- let config = match args.config_file.as_str() {
- "" => Config::find_config().unwrap_or_else(||
- panic!("Failed to find config. Paths searched: {:#?}", config::default_config_file_locations())),
- path => Config::parse_config_file_at_path(&path).unwrap_or_else(|err|
- panic!("Failed to parse config at {}. Error: {}", path, err)),
- };
+fn load_config(config_file_arg: &str) -> anyhow::Result<Config> {
+ match config_file_arg {
+ "" => Config::find_config().ok_or_else(||
+ anyhow!("Failed to find config. Paths searched: {:#?}", config::default_config_file_locations())),
+ path => Config::parse_config_file_at_path(path).map_err(|err|
+ anyhow!("Failed to parse config at {}. Error: {}", path, err)),
+ }
+}
+fn generate_channel(urls: Vec<String>, channel_config: ChannelConfig) -> Channel {
+ let mut channel = make_new_empty_channel(channel_config);
block_on(async {
- for channel in retrieve(config.urls.iter().map(AsRef::as_ref)).await {
- println!("{:#?}", channel);
- }
+ retrieve(urls.iter().map(AsRef::as_ref)).await.for_each(|c| {
+ channel.items.append(&mut c.into_items());
+ future::ready(())
+ }).await;
});
+ channel
+}
+
+fn write(channel: &Channel) {
+ let items_summary: Vec<(String, String)> = channel
+ .items().iter()
+ .map(|item| (
+ item.title().map(String::from).unwrap_or_else(String::new),
+ item.pub_date().map(String::from).unwrap_or_else(String::new)))
+ .collect();
+ println!("{:#?}", items_summary);
}