3 Commits

Author SHA1 Message Date
Lukas Wölfer
33180e95a3 Worked on fetching 2025-08-12 21:03:49 +02:00
Lukas Wölfer
f37ca5e627 Made watchdog less verbose 2025-08-01 16:21:31 +02:00
Lukas Wölfer
7ee8fb23d9 Added signature, official v0.1.0 2025-07-24 19:07:48 +02:00
6 changed files with 51 additions and 31 deletions

32
Cargo.lock generated
View File

@@ -274,22 +274,6 @@ dependencies = [
"syn 2.0.104", "syn 2.0.104",
] ]
[[package]]
name = "dancing-bot-teachers"
version = "0.1.0"
dependencies = [
"chrono",
"futures",
"mwbot",
"rand 0.9.2",
"reqwest",
"serde",
"thiserror 2.0.12",
"tokio",
"tracing",
"tracing-subscriber",
]
[[package]] [[package]]
name = "darling" name = "darling"
version = "0.14.4" version = "0.14.4"
@@ -2462,6 +2446,22 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "teachertracker-rs"
version = "0.1.2"
dependencies = [
"chrono",
"futures",
"mwbot",
"rand 0.9.2",
"reqwest",
"serde",
"thiserror 2.0.12",
"tokio",
"tracing",
"tracing-subscriber",
]
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.20.0" version = "3.20.0"

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "dancing-bot-teachers" name = "teachertracker-rs"
version = "0.1.0" version = "0.1.2"
edition = "2024" edition = "2024"
authors = ["Lukas Wölfer <coding@thasky.one>"] authors = ["Lukas Wölfer <coding@thasky.one>"]
description = "A MediaWiki bot that updates score information of teachers" description = "A MediaWiki bot that updates score information of teachers"

View File

@@ -17,7 +17,7 @@ use mwbot::{
Bot, Bot,
generators::{Generator, SortDirection, categories::CategoryMemberSort}, generators::{Generator, SortDirection, categories::CategoryMemberSort},
}; };
use std::{error::Error, path::Path}; use std::path::Path;
use crate::watchdog::watch_wanted; use crate::watchdog::watch_wanted;
@@ -41,12 +41,17 @@ fn list_teacher_pages(bot: &Bot) -> tokio::sync::mpsc::Receiver<Result<mwbot::Pa
pages.generate(bot) pages.generate(bot)
} }
#[must_use]
pub fn app_signature() -> String {
format!("{} [{}]", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
}
fn main() { fn main() {
tracing_subscriber::fmt() tracing_subscriber::fmt()
.with_level(true) .with_level(true)
.with_max_level(tracing::Level::INFO) .with_max_level(tracing::Level::INFO)
.init(); .init();
tracing::info!("Starting {}", app_signature());
let rt = match tokio::runtime::Builder::new_current_thread() let rt = match tokio::runtime::Builder::new_current_thread()
.enable_all() .enable_all()
.build() .build()

View File

@@ -12,7 +12,7 @@ pub async fn update_wsdc(bot: Bot) -> ! {
tracing::info!("We have to update {} pages", l.len()); tracing::info!("We have to update {} pages", l.len());
let wait_duration = Duration::from_secs(6 * 3600); let wait_duration = Duration::from_secs(6 * 3600);
for (index, page) in l { for (index, page) in l {
tracing::info!("Next up: {index}"); tracing::info!("Next up: #{index}");
tokio::time::sleep(wait_duration).await; tokio::time::sleep(wait_duration).await;
if generate_page(index, page).await { if generate_page(index, page).await {
tracing::info!("Updated {index}"); tracing::info!("Updated {index}");

View File

@@ -1,5 +1,6 @@
use std::time::Duration; use std::time::Duration;
use crate::app_signature;
use crate::{wikiinfo::wanted_ids, wikipage::page_from_info, worldsdc::fetch_wsdc_info}; use crate::{wikiinfo::wanted_ids, wikipage::page_from_info, worldsdc::fetch_wsdc_info};
use mwbot::Bot; use mwbot::Bot;
use mwbot::SaveOptions; use mwbot::SaveOptions;
@@ -10,11 +11,17 @@ pub async fn watch_wanted(bot: Bot) -> ! {
let _enter = span.enter(); let _enter = span.enter();
let mut ignored_ids = vec![]; let mut ignored_ids = vec![];
let mut watch_count = 0;
loop { loop {
if ignored_ids.is_empty() { watch_count += 1;
tracing::info!("Watchdog check..."); if watch_count >= 120 {
watch_count = 0;
let failed_id_info = if ignored_ids.is_empty() {
String::new()
} else { } else {
tracing::info!("Watchdog check [{} failed ids]...", ignored_ids.len()); format!("[{} failed ids]", ignored_ids.len())
};
tracing::info!("Watchdog check{failed_id_info}...");
} }
let wanted = wanted_ids(bot.clone()).await; let wanted = wanted_ids(bot.clone()).await;
let mut new_ignored = vec![]; let mut new_ignored = vec![];
@@ -50,7 +57,10 @@ pub async fn generate_page(id: u32, page: mwbot::Page) -> bool {
match page match page
.save( .save(
code, code,
&SaveOptions::summary("Created WSDC info from worldsdc.com") &SaveOptions::summary(&format!(
"Created WSDC info from worldsdc.com -- {}",
app_signature()
))
.mark_as_bot(true) .mark_as_bot(true)
.mark_as_minor(false), .mark_as_minor(false),
) )

View File

@@ -11,14 +11,17 @@ pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
.map_err(DanceInfoError::ClientBuild)?; .map_err(DanceInfoError::ClientBuild)?;
let mut params = HashMap::new(); let mut params = HashMap::new();
params.insert("q", id.to_string()); params.insert("num", id.to_string());
let response = client let request = client
.request( .request(
reqwest::Method::POST, reqwest::Method::POST,
"https://points.worldsdc.com/lookup2020/find", "https://points.worldsdc.com/lookup2020/find",
) )
.form(&params) .form(&params)
.send() .build()
.map_err(DanceInfoError::RequestBuild)?;
let response = client
.execute(request)
.await .await
.map_err(DanceInfoError::Request)?; .map_err(DanceInfoError::Request)?;
@@ -30,6 +33,8 @@ pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
pub enum DanceInfoError { pub enum DanceInfoError {
#[error("Failed to build client: {0}")] #[error("Failed to build client: {0}")]
ClientBuild(reqwest::Error), ClientBuild(reqwest::Error),
#[error("Failed to build request: {0}")]
RequestBuild(reqwest::Error),
#[error("Request error: {0}")] #[error("Request error: {0}")]
Request(reqwest::Error), Request(reqwest::Error),
#[error("Failed to parse response: {0}")] #[error("Failed to parse response: {0}")]