Compare commits
4 Commits
v0.1.0
...
22fa677d8a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22fa677d8a | ||
|
|
2faf8038fe | ||
|
|
33180e95a3 | ||
|
|
f37ca5e627 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2448,7 +2448,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "teachertracker-rs"
|
name = "teachertracker-rs"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"futures",
|
"futures",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "teachertracker-rs"
|
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"
|
||||||
|
|||||||
1
emeline.json
Normal file
1
emeline.json
Normal file
File diff suppressed because one or more lines are too long
@@ -51,6 +51,8 @@ pub struct CompState {
|
|||||||
pub rank: DanceRank,
|
pub rank: DanceRank,
|
||||||
pub points: u16,
|
pub points: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct DanceInfo {
|
pub struct DanceInfo {
|
||||||
pub firstname: String,
|
pub firstname: String,
|
||||||
pub lastname: String,
|
pub lastname: String,
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -11,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![];
|
||||||
|
|||||||
@@ -11,14 +11,20 @@ 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());
|
|
||||||
let response = client
|
let url = if cfg!(test) {
|
||||||
.request(
|
"https://o5grQU3Y.free.beeceptor.com/lookup2020/find"
|
||||||
reqwest::Method::POST,
|
} else {
|
||||||
"https://points.worldsdc.com/lookup2020/find",
|
"https://points.worldsdc.com/lookup2020/find"
|
||||||
)
|
};
|
||||||
|
params.insert("num", id.to_string());
|
||||||
|
let request = client
|
||||||
|
.request(reqwest::Method::POST, url)
|
||||||
.form(¶ms)
|
.form(¶ms)
|
||||||
.send()
|
.build()
|
||||||
|
.map_err(DanceInfoError::RequestBuild)?;
|
||||||
|
let response = client
|
||||||
|
.execute(request)
|
||||||
.await
|
.await
|
||||||
.map_err(DanceInfoError::Request)?;
|
.map_err(DanceInfoError::Request)?;
|
||||||
|
|
||||||
@@ -26,10 +32,36 @@ pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
|||||||
Ok(x.into())
|
Ok(x.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#![allow(clippy::unwrap_used, reason="Allow unwrap in tests")]
|
||||||
|
use crate::worldsdc::fetch_wsdc_info;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore = "Only run when the mock api is setup"]
|
||||||
|
fn test_fetch_wsdc() {
|
||||||
|
let rt = match tokio::runtime::Builder::new_current_thread()
|
||||||
|
.enable_all()
|
||||||
|
.build()
|
||||||
|
{
|
||||||
|
Ok(o) => o,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!("Could not start runtime: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let x = rt.block_on(fetch_wsdc_info(7));
|
||||||
|
dbg!(&x);
|
||||||
|
x.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
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}")]
|
||||||
|
|||||||
Reference in New Issue
Block a user