You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

68 lines
2.1 KiB

use dsbfnr::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 + re-encoder 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)
.min_values(1)
.help("select categories to fetch (format: either 'CATEGORY' or 'CATEGORY EXPECTED_MAX_ELEMS')"),
)
.get_matches();
let categories: Vec<_> = matches.values_of("categories").unwrap().collect();
curl::init();
let progbar_master = indicatif::MultiProgress::new();
let shared = Arc::new(fetch::SharedWorkerData {
destination: std::path::PathBuf::from(
matches.value_of("destdir").unwrap_or(".").to_string() + "/",
),
urlbase: url::Url::parse(&format!(
"https://app.dsbcontrol.de/data/{}/",
matches.value_of("dsbpath").unwrap()
))
.expect("invalid dsbpath"),
progbar_sum: progbar_master.add(indicatif::ProgressBar::new(0)),
cooldown_dur: std::time::Duration::from_micros(200),
});
shared.progbar_sum.set_style(dsbfnr::PROGBAR_STYLE.clone());
let ths: Vec<_> = categories
.iter()
.map(|cat| fetch::spawn_fetch_folder(shared.clone(), cat, &progbar_master))
.collect();
std::mem::drop(shared);
progbar_master.join().unwrap();
for i in ths.into_iter() {
i.join().unwrap();
}
}