Made parsoid work

This commit is contained in:
Lukas Wölfer
2025-07-21 01:53:23 +02:00
parent 7c3fc0a2ca
commit 7ce728ef8e
4 changed files with 740 additions and 196 deletions

47
src/old_style.rs Normal file
View File

@@ -0,0 +1,47 @@
use mwbot::{Bot, parsoid::WikinodeIterator as _};
fn extract_number_from_url(url: &str) -> Option<u32> {
// Split the URL into parts using '/'
let parts: Vec<&str> = url.split('/').collect();
// Iterate over the parts to find the one that ends with ".html"
for part in parts {
if part.ends_with(".html") {
// Remove the ".html" suffix
let number_str = part.trim_end_matches(".html");
// Parse the remaining string into an integer
return number_str.parse().ok();
}
}
None
}
pub async fn get_wsdc_id(bot: &Bot, page: &mwbot::Page) -> Option<u32> {
let x = page.html().await.unwrap().into_mutable();
for w in &x.filter_external_links() {
if let Some(id) = extract_number_from_url(&w.target()) {
return Some(id);
}
}
None
}
pub async fn get_description(bot: &Bot, page: &mwbot::Page) -> Option<String> {
let x = page.html().await.unwrap().into_mutable();
for w in &x.iter_sections() {
dbg!(w);
let Some(h) = w.heading() else {
println!("No heading");
continue;
};
dbg!(&h);
let Some(t) = h.as_text() else {
println!("No text");
continue;
};
dbg!(t.borrow());
}
None
}