Worked on login and teacher listing

This commit is contained in:
Lukas Wölfer
2025-07-21 00:27:19 +02:00
commit 7c3fc0a2ca
4 changed files with 2713 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/target
mwbot.toml

2641
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

8
Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "dancing-bot-teachers"
version = "0.1.0"
edition = "2024"
[dependencies]
mwbot = "0.6.1"
tokio = { version = "1.46.1", features = ["rt", "rt-multi-thread", "macros"] }

62
src/main.rs Normal file
View File

@@ -0,0 +1,62 @@
use mwbot::{
Bot,
generators::{CategoryMemberSort, Generator, SortDirection},
parsoid::{self, WikinodeIterator},
};
use std::{error::Error, path::Path};
fn list_teacher_pages(bot: &Bot) -> tokio::sync::mpsc::Receiver<Result<mwbot::Page, mwbot::Error>> {
let category_title = "Category:Teachers";
let pages = mwbot::generators::CategoryMembers::new(category_title)
.dir(SortDirection::Descending)
.sort(CategoryMemberSort::Timestamp);
println!("Pages in category 'Teachers':");
pages.generate(bot)
}
async fn print_teachers(bot: &Bot) {
while let Some(page) = list_teacher_pages(bot).recv().await {
let p = page.unwrap();
println!("- {}", p.as_title().dbkey());
print_wsdc_id(bot, &p).await;
}
}
async fn print_wsdc_id(bot: &Bot, page: &mwbot::Page) {
println!("{}", page.wikitext().await.unwrap());
let x = page.html().await.unwrap().into_mutable();
for w in &x.filter_external_links() {
println!("{}", w.text_contents());
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let bot = match Bot::from_path(Path::new("./mwbot.toml")).await {
Ok(x) => x,
Err(e) => {
dbg!(e);
return Ok(());
}
};
print_teachers(&bot).await;
Ok(())
// // Monitor changes on these pages
// for page_title in pages {
// let mut stream = bot.watch_page(&page_title).await?;
// tokio::spawn(async move {
// while let Some(change) = stream.next().await {
// println!("Change detected on {}: {:?}", page_title, change);
// }
// });
// }
// // Keep the main thread alive to continue monitoring
// loop {
// tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
// }
}