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.

91 lines
2.6KB

  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. .arg(
  33. Arg::with_name("eval-rooms")
  34. .short("r")
  35. .long("eval-rooms")
  36. .help("enable evaluation of rooms"),
  37. )
  38. .get_matches();
  39. let mut categories = vec!["r"];
  40. if let Some(ctgs) = matches.values_of("categories") {
  41. categories.extend(ctgs);
  42. }
  43. let destdir = Arc::new(std::path::PathBuf::from(
  44. matches.value_of("destdir").unwrap_or(".").to_string() + "/",
  45. ));
  46. let urlbase = Arc::new(
  47. url::Url::parse(&format!(
  48. "https://app.dsbcontrol.de/data/{}/",
  49. matches.value_of("dsbpath").unwrap()
  50. ))
  51. .expect("invalid dsbpath"),
  52. );
  53. curl::init();
  54. let progbar_master = indicatif::MultiProgress::new();
  55. let ths: Vec<_> = categories
  56. .iter()
  57. .map(|cat| {
  58. (
  59. cat,
  60. fetch::spawn_fetch_folder(&destdir, &urlbase, cat, &progbar_master),
  61. )
  62. })
  63. .collect();
  64. progbar_master.join_and_clear().unwrap();
  65. {
  66. let artific_bar = progbar_master.add(indicatif::ProgressBar::new_spinner());
  67. for i in ths.into_iter() {
  68. artific_bar.set_message(&format!("waiting for: {}", i.0));
  69. i.1.join().unwrap();
  70. artific_bar.set_message(&format!("done waiting for: {}", i.0));
  71. artific_bar.tick();
  72. }
  73. artific_bar.finish_with_message("done");
  74. }
  75. progbar_master.join_and_clear().unwrap();
  76. if matches.is_present("eval-rooms") {
  77. // TODO: impl eval-rooms
  78. unimplemented!();
  79. }
  80. }