--sync-url option

This commit is contained in:
FliegendeWurst 2021-04-19 10:33:46 +02:00
parent 450b0d9284
commit a05ea16d83

View File

@ -129,19 +129,29 @@ async fn main() {
} }
} }
let ilias = Arc::new(ilias); let ilias = Arc::new(ilias);
let desktop = ilias.personal_desktop().await.context("Failed to load personal desktop");
let (tx, mut rx) = futures_channel::mpsc::unbounded::<JoinHandle<()>>(); let (tx, mut rx) = futures_channel::mpsc::unbounded::<JoinHandle<()>>();
*TASKS.lock() = Some(tx.clone()); *TASKS.lock() = Some(tx.clone());
match desktop { if let Some(url) = ilias.opt.sync_url.as_ref() {
Ok(desktop) => { for item in ilias.get_course_content(&URL::from_href(url).expect("invalid URL")).await.expect("invalid response") {
for item in desktop.items { let item = item.expect("invalid item");
let mut path = ilias.opt.output.clone(); let ilias = Arc::clone(&ilias);
path.push(file_escape(item.name())); let mut path = ilias.opt.output.clone();
let ilias = Arc::clone(&ilias); path.push(file_escape(item.name()));
let _ = tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item))); tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item))).unwrap();
} }
}, } else {
Err(e) => error!(e), let desktop = ilias.personal_desktop().await.context("Failed to load personal desktop");
match desktop {
Ok(desktop) => {
for item in desktop.items {
let mut path = ilias.opt.output.clone();
path.push(file_escape(item.name()));
let ilias = Arc::clone(&ilias);
let _ = tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item)));
}
},
Err(e) => error!(e),
}
} }
while let Either::Left((task, _)) = future::select(rx.next(), future::ready(())).await { while let Either::Left((task, _)) = future::select(rx.next(), future::ready(())).await {
if let Some(task) = task { if let Some(task) = task {
@ -837,6 +847,10 @@ struct Opt {
/// KIT account password /// KIT account password
#[structopt(short = "P", long)] #[structopt(short = "P", long)]
password: Option<String>, password: Option<String>,
/// ILIAS page to download
#[structopt(long)]
sync_url: Option<String>,
} }
struct ILIAS { struct ILIAS {