|
|
- mod fetch;
-
- fn main() {
- use clap::Arg;
- use std::sync::Arc;
-
- let matches = clap::App::new("dsbfnr")
- .version(clap::crate_version!())
- .author("Erik Zscheile <erik.zscheile@gmail.com>")
- .about("a dsbcontrol.de CMS data fetcher + evaluator for personal purposes")
- .arg(
- Arg::with_name("destdir")
- .short("d")
- .long("destdir")
- .takes_value(true)
- .help("sets the destination dir (defaults to '.')"),
- )
- .arg(
- Arg::with_name("dsbpath")
- .short("k")
- .long("dsbpath")
- .takes_value(true)
- .required(true)
- .help("sets the DSB path / key (known format: 'ORGID/REVID/WEEK)"),
- )
- .arg(
- Arg::with_name("categories")
- .short("c")
- .long("categories")
- .takes_value(true)
- .multiple(true)
- .help("append additional categories ('r' will always be fetched)"),
- )
- .get_matches();
-
- let mut categories = vec!["r"];
- if let Some(ctgs) = matches.values_of("categories") {
- categories.extend(ctgs);
- }
-
- let destdir = Arc::new(std::path::PathBuf::from(
- matches.value_of("destdir").unwrap_or(".").to_string() + "/",
- ));
- let urlbase = Arc::new(
- url::Url::parse(&format!(
- "https://app.dsbcontrol.de/data/{}/",
- matches.value_of("dsbpath").unwrap()
- ))
- .expect("invalid dsbpath"),
- );
-
- curl::init();
- let progbar_master = indicatif::MultiProgress::new();
-
- let ths: Vec<_> = categories
- .iter()
- .map(|cat| {
- (
- cat,
- fetch::spawn_fetch_folder(&destdir, &urlbase, cat, &progbar_master),
- )
- })
- .collect();
-
- progbar_master.join_and_clear().unwrap();
-
- {
- let artific_bar = progbar_master.add(indicatif::ProgressBar::new_spinner());
- for i in ths.into_iter() {
- artific_bar.set_message(&format!("waiting for: {}", i.0));
- i.1.join().unwrap();
- artific_bar.set_message(&format!("done waiting for: {}", i.0));
- artific_bar.tick();
- }
- artific_bar.finish_with_message("done");
- }
-
- progbar_master.join_and_clear().unwrap();
- }
|