| 29 | } |
| 30 | |
| 31 | fn parse(html: &str) -> Vec<LicenseEntry> { |
| 32 | let document = Html::parse_document(html); |
| 33 | |
| 34 | let product_sel = Selector::parse("div.product").unwrap(); |
| 35 | let title_sel = Selector::parse("span.title").unwrap(); |
| 36 | let homepage_sel = Selector::parse("span.homepage a").unwrap(); |
| 37 | let license_sel = Selector::parse("div.license pre").unwrap(); |
| 38 | |
| 39 | document |
| 40 | .select(&product_sel) |
| 41 | .filter_map(|product| { |
| 42 | let name: String = product.select(&title_sel).next().map(|el| el.text().collect()).unwrap_or_default(); |
| 43 | |
| 44 | if name.is_empty() { |
| 45 | return None; |
| 46 | } |
| 47 | |
| 48 | let homepage = product.select(&homepage_sel).next().and_then(|el| el.value().attr("href").map(String::from)); |
| 49 | |
| 50 | let license_text: String = product.select(&license_sel).next().map(|el| el.text().collect::<String>()).unwrap_or_default().trim().to_string(); |
| 51 | |
| 52 | let pkg = Package { |
| 53 | name, |
| 54 | url: homepage, |
| 55 | authors: Vec::new(), |
| 56 | }; |
| 57 | |
| 58 | Some(LicenseEntry { |
| 59 | name: None, |
| 60 | text: license_text, |
| 61 | packages: vec![pkg], |
| 62 | }) |
| 63 | }) |
| 64 | .collect() |
| 65 | } |
| 66 | |
| 67 | fn read() -> Result<String, Error> { |
| 68 | let cef_path = PathBuf::from(env!("CEF_PATH")); |