Worked on login and teacher listing
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/target
|
||||
mwbot.toml
|
||||
2641
Cargo.lock
generated
Normal file
2641
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
8
Cargo.toml
Normal file
8
Cargo.toml
Normal 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
62
src/main.rs
Normal 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;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user