From 4a97f0a6597779de06a6367d5e7b7e15232658e2 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 6 Jan 2022 16:41:04 +0100 Subject: [PATCH] Properly extract dashboard items --- Cargo.lock | 1 + Cargo.toml | 1 + src/ilias.rs | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1e63117..679b6fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,6 +12,7 @@ dependencies = [ "cfg-if 1.0.0", "colored", "cookie_store", + "ego-tree", "futures", "futures-channel", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index a1c2f34..c51a35c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,3 +35,4 @@ reqwest_cookie_store = "0.2.0" bytes = "1.0.1" toml = "0.5.8" tempfile = "3.2.0" +ego-tree = "0.6.2" diff --git a/src/ilias.rs b/src/ilias.rs index d7df898..eb1fbaf 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -28,8 +28,9 @@ static ALERT_DANGER: Lazy = Lazy::new(|| Selector::parse("div.alert-da static IL_CONTENT_CONTAINER: Lazy = Lazy::new(|| Selector::parse("#il_center_col").unwrap()); static BLOCK_FAVORITES: Lazy = Lazy::new(|| Selector::parse("#block_pditems_0").unwrap()); static ITEM_PROP: Lazy = Lazy::new(|| Selector::parse("span.il_ItemProperty").unwrap()); -static CONTAINER_ITEMS: Lazy = Lazy::new(|| Selector::parse("div.il_ContainerListItem").unwrap()); +static CONTAINER_ITEMS: Lazy = Lazy::new(|| Selector::parse("div.il_ContainerListItem, .il-std-item").unwrap()); static CONTAINER_ITEM_TITLE: Lazy = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle").unwrap()); +static CONTAINER_ITEM_TITLE_ALTERNATIVE: Lazy = Lazy::new(|| Selector::parse(".il-item-title > a").unwrap()); pub struct ILIAS { pub opt: Opt, @@ -251,10 +252,16 @@ impl ILIAS { } pub fn get_items(html: &Html) -> Vec> { + let html = if let Some(favorites) = html.select(&BLOCK_FAVORITES).next() { + favorites + } else { + html.root_element() + }; html.select(&CONTAINER_ITEMS) .flat_map(|item| { item.select(&CONTAINER_ITEM_TITLE) .next() + .or_else(|| item.select(&CONTAINER_ITEM_TITLE_ALTERNATIVE).next()) .map(|link| Object::from_link(item, link)) // items without links are ignored })