From bc9530821d9526d6e84d78e8bdb36dabd1f17d27 Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Wed, 30 Oct 2024 15:15:38 -0400 Subject: [PATCH] feat(scraper): add output file --- src/scraper/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/scraper/main.rs b/src/scraper/main.rs index bf7ee76..b4c5f0a 100644 --- a/src/scraper/main.rs +++ b/src/scraper/main.rs @@ -18,6 +18,8 @@ struct Cli { #[arg(short = 'f', long = "format", value_enum)] format: Format, + #[arg(short = 'o', long = "output")] + output: Option, } #[derive(Debug, Clone, ValueEnum)] @@ -49,7 +51,7 @@ enum Format { #[tokio::main] async fn main() { let cli = Cli::parse(); - let (sub, final_count, sort, format) = (cli.sub, cli.count, cli.sort, cli.format); + let (sub, final_count, sort, format, output) = (cli.sub, cli.count, cli.sort, cli.format, cli.output); let initial = format!("/r/{sub}/{sort}.json?&raw_json=1"); let (mut posts, mut after) = Post::fetch(&initial, false).await.unwrap(); while posts.len() < final_count { @@ -65,7 +67,7 @@ async fn main() { match format { Format::Json => { - let filename: String = format!("{sub}.json"); + let filename: String = output.unwrap_or_else(|| format!("{sub}.json")); let json = serde_json::to_string(&posts).unwrap(); std::fs::write(filename, json).unwrap(); }