Properly extract dashboard items

This commit is contained in:
FliegendeWurst 2022-01-06 16:41:04 +01:00
parent cf28db189f
commit 4a97f0a659
3 changed files with 10 additions and 1 deletions

1
Cargo.lock generated
View File

@ -12,6 +12,7 @@ dependencies = [
"cfg-if 1.0.0",
"colored",
"cookie_store",
"ego-tree",
"futures",
"futures-channel",
"futures-util",

View File

@ -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"

View File

@ -28,8 +28,9 @@ static ALERT_DANGER: Lazy<Selector> = Lazy::new(|| Selector::parse("div.alert-da
static IL_CONTENT_CONTAINER: Lazy<Selector> = Lazy::new(|| Selector::parse("#il_center_col").unwrap());
static BLOCK_FAVORITES: Lazy<Selector> = Lazy::new(|| Selector::parse("#block_pditems_0").unwrap());
static ITEM_PROP: Lazy<Selector> = Lazy::new(|| Selector::parse("span.il_ItemProperty").unwrap());
static CONTAINER_ITEMS: Lazy<Selector> = Lazy::new(|| Selector::parse("div.il_ContainerListItem").unwrap());
static CONTAINER_ITEMS: Lazy<Selector> = Lazy::new(|| Selector::parse("div.il_ContainerListItem, .il-std-item").unwrap());
static CONTAINER_ITEM_TITLE: Lazy<Selector> = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle").unwrap());
static CONTAINER_ITEM_TITLE_ALTERNATIVE: Lazy<Selector> = 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<Result<Object>> {
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
})