Updated dependencies; crash on logout to login on restart; moving back to worldsdc API

This commit is contained in:
Lukas Wölfer
2026-01-17 00:46:28 +01:00
parent 5414a1bb26
commit 31293d1807
8 changed files with 856 additions and 562 deletions

1322
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -12,6 +12,7 @@ categories = ["web-programming", "api-bindings", "automation"]
[dependencies] [dependencies]
chrono = "0.4.41" chrono = "0.4.41"
clap = { version = "4.5.54", features = ["derive"] }
futures = "0.3.31" futures = "0.3.31"
# mwbot = { git = "https://gitlab.wikimedia.org/repos/mwbot-rs/mwbot.git", rev = "05cbb12188f18e2da710de158d89a9a4f1b42689", default-features = false, features = ["generators", "mwbot_derive"] } # mwbot = { git = "https://gitlab.wikimedia.org/repos/mwbot-rs/mwbot.git", rev = "05cbb12188f18e2da710de158d89a9a4f1b42689", default-features = false, features = ["generators", "mwbot_derive"] }
mwbot = { version = "0.7.0", default-features = false, features = ["generators", "mwbot_derive"] } mwbot = { version = "0.7.0", default-features = false, features = ["generators", "mwbot_derive"] }

1
robert-2026-01-07.html Normal file

File diff suppressed because one or more lines are too long

View File

@@ -16,7 +16,6 @@
clippy::cast_possible_wrap, clippy::cast_possible_wrap,
reason = "Disable this for most of the time, enable this for cleanup later" reason = "Disable this for most of the time, enable this for cleanup later"
)] )]
#![feature(hash_map_macro)]
#![feature(never_type)] #![feature(never_type)]
use mwbot::{ use mwbot::{
@@ -27,7 +26,7 @@ use std::path::Path;
use tracing::level_filters::LevelFilter; use tracing::level_filters::LevelFilter;
use tracing_subscriber::{Layer, layer::SubscriberExt, util::SubscriberInitExt}; use tracing_subscriber::{Layer, layer::SubscriberExt, util::SubscriberInitExt};
use crate::watchdog::watch_wanted; use crate::watchdog::{update_wanted_ids, watch_wanted};
mod dance_info; mod dance_info;
mod updater; mod updater;
@@ -62,13 +61,13 @@ pub enum AppError {
BotError(#[from] ConfigError), BotError(#[from] ConfigError),
} }
fn main() -> Result<(), AppError> { fn init_sentry() -> Option<sentry::ClientInitGuard> {
let fmt_filter = tracing_subscriber::fmt::layer().with_filter( let fmt_filter = tracing_subscriber::fmt::layer().with_filter(
tracing_subscriber::EnvFilter::builder() tracing_subscriber::EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into()) .with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(), .from_env_lossy(),
); );
let _guard = match std::fs::read_to_string("sentry_dsn.txt") { let guard: Option<sentry::ClientInitGuard> = match std::fs::read_to_string("sentry_dsn.txt") {
Ok(dsn) => { Ok(dsn) => {
let guard = sentry::init(( let guard = sentry::init((
dsn, dsn,
@@ -102,19 +101,64 @@ fn main() -> Result<(), AppError> {
None None
} }
}; };
guard
}
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "myapp")]
#[command(about = "A simple CLI app with subcommands", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
/// Build pages for all missing teachers
Missing,
}
fn main() -> Result<(), AppError> {
let _guard = init_sentry();
// Register the Sentry tracing layer to capture breadcrumbs, events, and spans: // Register the Sentry tracing layer to capture breadcrumbs, events, and spans:
let rt = tokio::runtime::Builder::new_current_thread() let rt = tokio::runtime::Builder::new_current_thread()
.enable_all() .enable_all()
.build()?; .build()?;
let cli = Cli::parse();
let bot = rt.block_on(Bot::from_path(Path::new("./mwbot.toml")))?; let bot = rt.block_on(Bot::from_path(Path::new("./mwbot.toml")))?;
match &cli.command {
Some(Commands::Missing) => {
rt.block_on(async {
let wanted = wikiinfo::wanted_ids(bot.clone()).await;
tracing::info!(
"Missing ids: {}",
wanted
.iter()
.map(|(v, _)| v)
.map(u32::to_string)
.collect::<Vec<_>>()
.join("\n")
);
update_wanted_ids(&wanted, &[]).await;
});
return Ok(());
}
None => {
#[allow( #[allow(
unreachable_code, unreachable_code,
reason = "This is a false positive I think, I just want to loop infinitely on two futures" reason = "This is a false positive I think, I just want to loop infinitely on two futures"
)] )]
rt.block_on(async { futures::join!(watch_wanted(bot.clone()), updater::update_wsdc(bot)) }); rt.block_on(async {
futures::join!(watch_wanted(bot.clone()), updater::update_wsdc(bot))
Ok(()) });
}
}
unreachable!();
} }

View File

@@ -45,10 +45,10 @@ pub async fn watch_wanted(bot: Bot) -> ! {
} }
} }
async fn update_wanted_ids(wanted: &[(u32, Page)], ignored_ids: &[u32]) -> Vec<u32> { pub async fn update_wanted_ids(wanted: &[(u32, Page)], ignored_ids: &[u32]) -> Vec<u32> {
let mut new_ignored = vec![]; let mut new_ignored = vec![];
for (id, page) in wanted.iter().filter(|(x, _)| ignored_ids.contains(x)) { for (id, page) in wanted.iter().filter(|(x, _)| !ignored_ids.contains(x)) {
let span = tracing::info_span!("update", id); let span = tracing::info_span!("update", id);
let _enter = span.enter(); let _enter = span.enter();
if let Err(e) = generate_page(*id, page.clone()).await { if let Err(e) = generate_page(*id, page.clone()).await {

View File

@@ -10,7 +10,15 @@ pub async fn wanted_ids(bot: Bot) -> Vec<(u32, Page)> {
let p = match x { let p = match x {
Ok(p) => p, Ok(p) => p,
Err(e) => { Err(e) => {
match e {
mwbot::Error::ApiError(a) if &a.code == "assertuserfailed" => {
tracing::error!("Bot is logged out: {a}");
panic!();
}
_ => {
tracing::error!("Could not get search result: {e}"); tracing::error!("Could not get search result: {e}");
}
}
continue; continue;
} }
}; };

View File

@@ -38,7 +38,8 @@ pub async fn fetch_wsdc_info_wsdc(id: u32) -> Result<DanceInfo, DanceInfoError>
} }
pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> { pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
fetch_wsdc_info_scoring_dance(id).await // fetch_wsdc_info_scoring_dance(id).await
fetch_wsdc_info_wsdc(id).await
} }
#[cfg(test)] #[cfg(test)]

View File

@@ -140,14 +140,21 @@ fn parse_stats(
} }
fn extract_tables(html: &str) -> Result<Vec<(String, Vec<Vec<String>>)>, ScoringParseError> { fn extract_tables(html: &str) -> Result<Vec<(String, Vec<Vec<String>>)>, ScoringParseError> {
dbg!(&html);
let document = Html::parse_document(html); let document = Html::parse_document(html);
let card_selector = Selector::parse("div:has( > div.card-header)").unwrap(); let card_selector = Selector::parse("div:has( > div.card-header)").unwrap();
document
document.select(&card_selector).map(parse_card).collect() .select(&card_selector)
.inspect(|v| {
dbg!(&v);
})
.map(parse_card)
.collect()
} }
fn parse_info(html: &str) -> Result<DanceInfo, ScoringParseError> { fn parse_info(html: &str) -> Result<DanceInfo, ScoringParseError> {
let tables = extract_tables(html)?; let tables = extract_tables(html)?;
dbg!(&tables);
let details = &tables let details = &tables
.iter() .iter()
.find(|(v, _)| v.to_lowercase().contains("detail")) .find(|(v, _)| v.to_lowercase().contains("detail"))
@@ -173,7 +180,7 @@ fn parse_info(html: &str) -> Result<DanceInfo, ScoringParseError> {
#[test] #[test]
fn test_parse_table() { fn test_parse_table() {
dbg!(parse_info(include_str!("../../polina.html"))); dbg!(parse_info(include_str!("../../robert-2026-01-07.html")));
} }
pub async fn fetch_wsdc_info_scoring_dance(id: u32) -> Result<DanceInfo, DanceInfoError> { pub async fn fetch_wsdc_info_scoring_dance(id: u32) -> Result<DanceInfo, DanceInfoError> {