5 Commits

Author SHA1 Message Date
Lukas Wölfer
7baff3a50c Release v0.1.4 2026-01-17 00:47:53 +01:00
Lukas Wölfer
31293d1807 Updated dependencies; crash on logout to login on restart; moving back to worldsdc API 2026-01-17 00:46:28 +01:00
Lukas Wölfer
5414a1bb26 Enable sentry reporting 2025-11-22 00:19:14 +01:00
Lukas Wölfer
c45001cb6d Improved rank parsing 2025-10-27 22:10:42 +01:00
Lukas Wölfer
5fae51248a More verbose request error output 2025-10-05 17:16:11 +02:00
9 changed files with 1682 additions and 580 deletions

2113
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
[package]
name = "teachertracker-rs"
version = "0.1.3"
version = "0.1.4"
edition = "2024"
authors = ["Lukas Wölfer <coding@thasky.one>"]
description = "A MediaWiki bot that updates score information of teachers"
@@ -12,12 +12,15 @@ categories = ["web-programming", "api-bindings", "automation"]
[dependencies]
chrono = "0.4.41"
clap = { version = "4.5.54", features = ["derive"] }
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 = { version = "0.7.0", default-features = false, features = ["generators", "mwbot_derive"] }
rand = "0.9.2"
reqwest = "0.12.22"
scraper = "0.24.0"
sentry = { version = "0.45.0", features = ["tracing"] }
sentry-tracing = { version = "0.45.0", features = ["backtrace", "logs"] }
serde = { version = "1.0.219", features = ["derive"] }
serde_plain = "1.0.2"
thiserror = "2.0.12"

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

File diff suppressed because one or more lines are too long

View File

@@ -24,7 +24,7 @@ pub enum DanceRank {
Newcomer,
Novice,
Intermediate,
#[serde(rename = "Advance")]
#[serde(rename = "Advance", alias = "Advanced")]
Advanced,
#[serde(rename = "All Star", alias = "All-Stars")]
AllStars,

View File

@@ -16,7 +16,6 @@
clippy::cast_possible_wrap,
reason = "Disable this for most of the time, enable this for cleanup later"
)]
#![feature(hash_map_macro)]
#![feature(never_type)]
use mwbot::{
@@ -24,8 +23,10 @@ use mwbot::{
generators::{Generator, SortDirection, categories::CategoryMemberSort},
};
use std::path::Path;
use tracing::level_filters::LevelFilter;
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 updater;
@@ -60,24 +61,104 @@ pub enum AppError {
BotError(#[from] ConfigError),
}
fn main() -> Result<(), AppError> {
tracing_subscriber::fmt()
.with_level(true)
.with_max_level(tracing::Level::INFO)
.init();
tracing::info!("Starting {}", app_signature());
fn init_sentry() -> Option<sentry::ClientInitGuard> {
let fmt_filter = tracing_subscriber::fmt::layer().with_filter(
tracing_subscriber::EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
);
let guard: Option<sentry::ClientInitGuard> = match std::fs::read_to_string("sentry_dsn.txt") {
Ok(dsn) => {
let guard = sentry::init((
dsn,
sentry::ClientOptions {
release: sentry::release_name!(),
traces_sample_rate: 1.0,
..Default::default()
},
));
let sentry_layer = sentry::integrations::tracing::layer()
.event_filter(|md| match *md.level() {
tracing::Level::ERROR => sentry_tracing::EventFilter::Event,
_ => sentry_tracing::EventFilter::Ignore,
})
.span_filter(|md| {
matches!(*md.level(), tracing::Level::ERROR | tracing::Level::WARN)
});
tracing_subscriber::registry()
.with(fmt_filter)
.with(sentry_layer)
.init();
tracing::info!("Starting {} with sentry", app_signature());
Some(guard)
}
Err(error) => {
tracing_subscriber::registry().with(fmt_filter).init();
tracing::warn!("Could not load 'sentry_dsn.txt': {}", error);
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:
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;
let cli = Cli::parse();
let bot = rt.block_on(Bot::from_path(Path::new("./mwbot.toml")))?;
#[allow(
unreachable_code,
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)) });
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;
});
Ok(())
return Ok(());
}
None => {
#[allow(
unreachable_code,
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))
});
}
}
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![];
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 _enter = span.enter();
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 {
Ok(p) => p,
Err(e) => {
tracing::error!("Could not get search result: {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}");
}
}
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> {
fetch_wsdc_info_scoring_dance(id).await
// fetch_wsdc_info_scoring_dance(id).await
fetch_wsdc_info_wsdc(id).await
}
#[cfg(test)]
@@ -71,7 +72,7 @@ pub enum DanceInfoError {
ClientBuild(reqwest::Error),
#[error("Failed to build request: {0}")]
RequestBuild(reqwest::Error),
#[error("Request error: {0}")]
#[error("Request error: {0:#?}")]
Request(reqwest::Error),
#[error("Failed to parse response: {0}")]
JsonParse(reqwest::Error),

View File

@@ -140,14 +140,21 @@ fn parse_stats(
}
fn extract_tables(html: &str) -> Result<Vec<(String, Vec<Vec<String>>)>, ScoringParseError> {
dbg!(&html);
let document = Html::parse_document(html);
let card_selector = Selector::parse("div:has( > div.card-header)").unwrap();
document.select(&card_selector).map(parse_card).collect()
document
.select(&card_selector)
.inspect(|v| {
dbg!(&v);
})
.map(parse_card)
.collect()
}
fn parse_info(html: &str) -> Result<DanceInfo, ScoringParseError> {
let tables = extract_tables(html)?;
dbg!(&tables);
let details = &tables
.iter()
.find(|(v, _)| v.to_lowercase().contains("detail"))
@@ -173,7 +180,7 @@ fn parse_info(html: &str) -> Result<DanceInfo, ScoringParseError> {
#[test]
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> {