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.

79 lines
2.3 KiB

3 years ago
  1. mod fetch;
  2. fn main() {
  3. use clap::Arg;
  4. use std::sync::Arc;
  5. let matches = clap::App::new("dsbfnr")
  6. .version(clap::crate_version!())
  7. .author("Erik Zscheile <erik.zscheile@gmail.com>")
  8. .about("a dsbcontrol.de CMS data fetcher + evaluator for personal purposes")
  9. .arg(
  10. Arg::with_name("destdir")
  11. .short("d")
  12. .long("destdir")
  13. .takes_value(true)
  14. .help("sets the destination dir (defaults to '.')"),
  15. )
  16. .arg(
  17. Arg::with_name("dsbpath")
  18. .short("k")
  19. .long("dsbpath")
  20. .takes_value(true)
  21. .required(true)
  22. .help("sets the DSB path / key (known format: 'ORGID/REVID/WEEK)"),
  23. )
  24. .arg(
  25. Arg::with_name("categories")
  26. .short("c")
  27. .long("categories")
  28. .takes_value(true)
  29. .multiple(true)
  30. .help("append additional categories ('r' will always be fetched)"),
  31. )
  32. .get_matches();
  33. let mut categories = vec!["r"];
  34. if let Some(ctgs) = matches.values_of("categories") {
  35. categories.extend(ctgs);
  36. }
  37. let destdir = Arc::new(std::path::PathBuf::from(
  38. matches.value_of("destdir").unwrap_or(".").to_string() + "/",
  39. ));
  40. let urlbase = Arc::new(
  41. url::Url::parse(&format!(
  42. "https://app.dsbcontrol.de/data/{}/",
  43. matches.value_of("dsbpath").unwrap()
  44. ))
  45. .expect("invalid dsbpath"),
  46. );
  47. curl::init();
  48. let progbar_master = indicatif::MultiProgress::new();
  49. let ths: Vec<_> = categories
  50. .iter()
  51. .map(|cat| {
  52. (
  53. cat,
  54. fetch::spawn_fetch_folder(&destdir, &urlbase, cat, &progbar_master),
  55. )
  56. })
  57. .collect();
  58. progbar_master.join_and_clear().unwrap();
  59. {
  60. let artific_bar = progbar_master.add(indicatif::ProgressBar::new_spinner());
  61. for i in ths.into_iter() {
  62. artific_bar.set_message(&format!("waiting for: {}", i.0));
  63. i.1.join().unwrap();
  64. artific_bar.set_message(&format!("done waiting for: {}", i.0));
  65. artific_bar.tick();
  66. }
  67. artific_bar.finish_with_message("done");
  68. }
  69. progbar_master.join_and_clear().unwrap();
  70. }