add help switch

This commit is contained in:
theBreadCompany 2024-11-18 09:56:55 +01:00
parent ad7ab65366
commit 63acd248ec

View file

@ -20,7 +20,7 @@ async fn main() {
write_all().await; write_all().await;
} }
"--help" => { "--help" => {
panic!("not implemented"); print_help();
} }
_ => { _ => {
panic!("bad command {}", cmd); panic!("bad command {}", cmd);
@ -53,6 +53,20 @@ async fn main() {
} }
} }
fn print_help() {
println!(
r"
Usage: sfwikiscraper <options>
--help: display this help
--all: fetch all recipes
--tier <tier>: fetches all recipes of the nth tier
--item <url>: fetches the recipe (only by url for now)
--test <url>: parse the json format shipped in <url>
"
);
}
async fn fetch_data(url: String) -> Vec<Value> { async fn fetch_data(url: String) -> Vec<Value> {
let webdata = reqwest::get(url) let webdata = reqwest::get(url)
.await .await
@ -150,11 +164,14 @@ async fn write_all() {
&join_all( &join_all(
(0..9) (0..9)
.into_iter() .into_iter()
.map(|i| async move { fetch_tier(i.to_string()).await }) .map(|i| async move { fetch_tier(i.to_string()).await }),
) )
.await .await
.into_iter() .into_iter()
.reduce(|mut acc, e| { acc.extend(e.iter().cloned()); acc }) .reduce(|mut acc, e| {
acc.extend(e.iter().cloned());
acc
}),
) )
.unwrap() .unwrap()
.as_bytes(), .as_bytes(),