Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6561471e8b | |||
| e16878c947 | |||
| 5a308b5b4c | |||
| 1422183a90 | |||
| ffb926b2a2 | |||
| 9736adf7b2 | |||
| 215c355f6f | |||
| c1904e4589 | |||
|
|
eb88c041f6 | ||
|
|
596f1b3a6b | ||
|
|
6f332b314d | ||
|
|
46dc757bb7 | ||
|
|
b869842aa3 | ||
|
|
a2642f6b9a | ||
|
|
3d66841e74 | ||
|
|
0d88629b17 | ||
|
|
681cc0f59d |
38
.gitea/workflows/release.yaml
Normal file
38
.gitea/workflows/release.yaml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*.*.*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
GITEA_SERVER: ${{ secrets.GITEA_SERVER }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
|
||||||
|
- name: Build release
|
||||||
|
run: |
|
||||||
|
cargo build --release
|
||||||
|
- name: Generate a changelog
|
||||||
|
uses: orhun/git-cliff-action@v4
|
||||||
|
id: git-cliff
|
||||||
|
with:
|
||||||
|
config: cliff.toml
|
||||||
|
args: --verbose --latest
|
||||||
|
github_token: ""
|
||||||
|
env:
|
||||||
|
OUTPUT: CHANGELOG.md
|
||||||
|
- uses: akkuman/gitea-release-action@v1
|
||||||
|
with:
|
||||||
|
files: |-
|
||||||
|
target/release/teachertracker-rs
|
||||||
|
body: ${{ steps.git-cliff.outputs.content }}
|
||||||
13
.gitea/workflows/test.yaml
Normal file
13
.gitea/workflows/test.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
name: Rust
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
- run: cargo test --all-features
|
||||||
19
.scripts/commit-msg
Normal file
19
.scripts/commit-msg
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Path to the commit message file
|
||||||
|
COMMIT_MSG_FILE=$1
|
||||||
|
|
||||||
|
# Read the commit message
|
||||||
|
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
|
||||||
|
|
||||||
|
# Regex pattern for Conventional Commits
|
||||||
|
# Example: "feat: add new feature" or "fix!: break everything"
|
||||||
|
PATTERN='^(feat|fix|docs|style|refactor|perf|test|chore|revert|build|ci|wip|workflow)(\(.*\))?([!]?): .{1,}$'
|
||||||
|
|
||||||
|
if ! echo "$COMMIT_MSG" | grep -Eq "$PATTERN"; then
|
||||||
|
echo "❌ Invalid commit message format."
|
||||||
|
echo "Please follow the Conventional Commits specification: https://www.conventionalcommits.org/"
|
||||||
|
echo "Example: 'feat: add new feature'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
14
Cargo.lock
generated
14
Cargo.lock
generated
@@ -245,6 +245,17 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "async-trait"
|
||||||
|
version = "0.1.89"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.114",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atomic-waker"
|
name = "atomic-waker"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
@@ -3190,8 +3201,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "teachertracker-rs"
|
name = "teachertracker-rs"
|
||||||
version = "0.1.4"
|
version = "0.1.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"futures",
|
"futures",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "teachertracker-rs"
|
name = "teachertracker-rs"
|
||||||
version = "0.1.4"
|
version = "0.1.7"
|
||||||
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"
|
||||||
@@ -14,8 +14,7 @@ categories = ["web-programming", "api-bindings", "automation"]
|
|||||||
chrono = "0.4.41"
|
chrono = "0.4.41"
|
||||||
clap = { version = "4.5.54", features = ["derive"] }
|
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 = { version = "0.7.1", default-features = false, features = ["generators", "mwbot_derive"] }
|
||||||
mwbot = { version = "0.7.0", default-features = false, features = ["generators", "mwbot_derive"] }
|
|
||||||
rand = "0.9.2"
|
rand = "0.9.2"
|
||||||
reqwest = "0.12.22"
|
reqwest = "0.12.22"
|
||||||
scraper = "0.24.0"
|
scraper = "0.24.0"
|
||||||
@@ -27,3 +26,4 @@ thiserror = "2.0.12"
|
|||||||
tokio = { version = "1.46.1", features = ["rt"] }
|
tokio = { version = "1.46.1", features = ["rt"] }
|
||||||
tracing = { version = "0.1.41", default-features = false, features = ["std"] }
|
tracing = { version = "0.1.41", default-features = false, features = ["std"] }
|
||||||
tracing-subscriber = "0.3.19"
|
tracing-subscriber = "0.3.19"
|
||||||
|
async-trait = "0.1.79"
|
||||||
|
|||||||
94
cliff.toml
Normal file
94
cliff.toml
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
# git-cliff ~ configuration file
|
||||||
|
# https://git-cliff.org/docs/configuration
|
||||||
|
|
||||||
|
|
||||||
|
[changelog]
|
||||||
|
# A Tera template to be rendered for each release in the changelog.
|
||||||
|
# See https://keats.github.io/tera/docs/#introduction
|
||||||
|
body = """
|
||||||
|
{% if version %}\
|
||||||
|
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
|
||||||
|
{% else %}\
|
||||||
|
## [unreleased]
|
||||||
|
{% endif %}\
|
||||||
|
{% for group, commits in commits | group_by(attribute="group") %}
|
||||||
|
### {{ group | striptags | trim | upper_first }}
|
||||||
|
{% for commit in commits %}
|
||||||
|
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
|
||||||
|
{% if commit.breaking %}[**breaking**] {% endif %}\
|
||||||
|
{{ commit.message | upper_first }}\
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
"""
|
||||||
|
# Remove leading and trailing whitespaces from the changelog's body.
|
||||||
|
trim = true
|
||||||
|
# Render body even when there are no releases to process.
|
||||||
|
render_always = true
|
||||||
|
# An array of regex based postprocessors to modify the changelog.
|
||||||
|
postprocessors = [
|
||||||
|
# Replace the placeholder <REPO> with a URL.
|
||||||
|
#{ pattern = '<REPO>', replace = "https://github.com/orhun/git-cliff" },
|
||||||
|
]
|
||||||
|
# render body even when there are no releases to process
|
||||||
|
# render_always = true
|
||||||
|
# output file path
|
||||||
|
# output = "test.md"
|
||||||
|
|
||||||
|
[git]
|
||||||
|
# Parse commits according to the conventional commits specification.
|
||||||
|
# See https://www.conventionalcommits.org
|
||||||
|
conventional_commits = true
|
||||||
|
# Exclude commits that do not match the conventional commits specification.
|
||||||
|
filter_unconventional = false
|
||||||
|
# Require all commits to be conventional.
|
||||||
|
# Takes precedence over filter_unconventional.
|
||||||
|
require_conventional = false
|
||||||
|
# Split commits on newlines, treating each line as an individual commit.
|
||||||
|
split_commits = false
|
||||||
|
# An array of regex based parsers to modify commit messages prior to further processing.
|
||||||
|
commit_preprocessors = [
|
||||||
|
# Replace issue numbers with link templates to be updated in `changelog.postprocessors`.
|
||||||
|
#{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"},
|
||||||
|
# Check spelling of the commit message using https://github.com/crate-ci/typos.
|
||||||
|
# If the spelling is incorrect, it will be fixed automatically.
|
||||||
|
#{ pattern = '.*', replace_command = 'typos --write-changes -' },
|
||||||
|
]
|
||||||
|
# Prevent commits that are breaking from being excluded by commit parsers.
|
||||||
|
protect_breaking_commits = false
|
||||||
|
# An array of regex based parsers for extracting data from the commit message.
|
||||||
|
# Assigns commits to groups.
|
||||||
|
# Optionally sets the commit's scope and can decide to exclude commits from further processing.
|
||||||
|
commit_parsers = [
|
||||||
|
{ message = "^feat", group = "<!-- 0 -->🚀 Features" },
|
||||||
|
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
|
||||||
|
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" },
|
||||||
|
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" },
|
||||||
|
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
|
||||||
|
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
|
||||||
|
{ message = "^test", group = "<!-- 6 -->🧪 Testing" },
|
||||||
|
{ message = "^chore\\(release\\): prepare for", skip = true },
|
||||||
|
{ message = "^chore\\(deps.*\\)", skip = true },
|
||||||
|
{ message = "^chore\\(pr\\)", skip = true },
|
||||||
|
{ message = "^chore\\(pull\\)", skip = true },
|
||||||
|
{ message = "^chore|^ci", group = "<!-- 7 -->⚙️ Miscellaneous Tasks" },
|
||||||
|
{ body = ".*security", group = "<!-- 8 -->🛡️ Security" },
|
||||||
|
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
|
||||||
|
{ message = ".*", group = "<!-- 10 -->💼 Other" },
|
||||||
|
]
|
||||||
|
# Exclude commits that are not matched by any commit parser.
|
||||||
|
filter_commits = false
|
||||||
|
# Fail on a commit that is not matched by any commit parser.
|
||||||
|
fail_on_unmatched_commit = false
|
||||||
|
# An array of link parsers for extracting external references, and turning them into URLs, using regex.
|
||||||
|
link_parsers = []
|
||||||
|
# Include only the tags that belong to the current branch.
|
||||||
|
use_branch_tags = false
|
||||||
|
# Order releases topologically instead of chronologically.
|
||||||
|
topo_order = false
|
||||||
|
# Order commits topologically instead of chronologically.
|
||||||
|
topo_order_commits = true
|
||||||
|
# Order of commits in each group/release within the changelog.
|
||||||
|
# Allowed values: newest, oldest
|
||||||
|
sort_commits = "oldest"
|
||||||
|
# Process submodules commits
|
||||||
|
recurse_submodules = false
|
||||||
1
idea.md
1
idea.md
@@ -1 +0,0 @@
|
|||||||
https://dancing.thasky.one/api.php?action=query&format=json&list=querypage&formatversion=2&qppage=Wantedpages
|
|
||||||
34
src/fetching/mod.rs
Normal file
34
src/fetching/mod.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
use crate::dance_info::DanceInfo;
|
||||||
|
use crate::fetching::types::DanceInfoError;
|
||||||
|
|
||||||
|
mod scoringdance;
|
||||||
|
mod worldsdc;
|
||||||
|
pub mod types;
|
||||||
|
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait WsdcFetcher: Send + Sync {
|
||||||
|
async fn fetch(&self, id: u32) -> Result<DanceInfo, DanceInfoError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WorldsdcFetcher;
|
||||||
|
pub struct ScoringDanceFetcher;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl WsdcFetcher for WorldsdcFetcher {
|
||||||
|
async fn fetch(&self, id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||||
|
worldsdc::fetch_wsdc_info_wsdc(id).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl WsdcFetcher for ScoringDanceFetcher {
|
||||||
|
async fn fetch(&self, id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||||
|
scoringdance::fetch_wsdc_info_scoring_dance(id).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience alias for a shared, dynamic fetcher
|
||||||
|
pub type DynWsdcFetcher = Arc<dyn WsdcFetcher>;
|
||||||
@@ -6,7 +6,7 @@ use scraper::{ElementRef, Html, Selector};
|
|||||||
use crate::{
|
use crate::{
|
||||||
app_signature,
|
app_signature,
|
||||||
dance_info::{CompState, DanceInfo, DanceRank, DanceRole},
|
dance_info::{CompState, DanceInfo, DanceRank, DanceRole},
|
||||||
worldsdc::DanceInfoError,
|
fetching::DanceInfoError,
|
||||||
};
|
};
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum ScoringParseError {
|
pub enum ScoringParseError {
|
||||||
@@ -135,26 +135,16 @@ fn parse_stats(
|
|||||||
rank: *rank,
|
rank: *rank,
|
||||||
});
|
});
|
||||||
Ok((primary_role, dominant_comp, non_dominant_comp))
|
Ok((primary_role, dominant_comp, non_dominant_comp))
|
||||||
|
|
||||||
// dbg!(chapters.collect::<Vec<_>>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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"))
|
||||||
@@ -178,11 +168,6 @@ fn parse_info(html: &str) -> Result<DanceInfo, ScoringParseError> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_table() {
|
|
||||||
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> {
|
||||||
let client = ClientBuilder::new()
|
let client = ClientBuilder::new()
|
||||||
.user_agent(app_signature())
|
.user_agent(app_signature())
|
||||||
@@ -201,3 +186,16 @@ pub async fn fetch_wsdc_info_scoring_dance(id: u32) -> Result<DanceInfo, DanceIn
|
|||||||
|
|
||||||
parse_info(response.text().await.unwrap().as_str()).map_err(DanceInfoError::HtmlParse)
|
parse_info(response.text().await.unwrap().as_str()).map_err(DanceInfoError::HtmlParse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#![allow(clippy::unwrap_used)]
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_table() {
|
||||||
|
let info = parse_info(include_str!("../../test_data/2025-10-02_polina.html")).unwrap();
|
||||||
|
assert_eq!(info.firstname, "Polina");
|
||||||
|
assert_eq!(info.lastname, "Gorushkina");
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/fetching/types.rs
Normal file
13
src/fetching/types.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
pub enum DanceInfoError {
|
||||||
|
#[error("Failed to build client: {0}")]
|
||||||
|
ClientBuild(reqwest::Error),
|
||||||
|
#[error("Failed to build request: {0}")]
|
||||||
|
RequestBuild(reqwest::Error),
|
||||||
|
#[error("Request error: {0:#?}")]
|
||||||
|
Request(reqwest::Error),
|
||||||
|
#[error("Failed to parse response: {0}")]
|
||||||
|
JsonParse(reqwest::Error),
|
||||||
|
#[error("Failed to parse html: {0}")]
|
||||||
|
HtmlParse(#[from] super::scoringdance::ScoringParseError),
|
||||||
|
}
|
||||||
@@ -3,10 +3,9 @@ use std::collections::HashMap;
|
|||||||
use crate::{
|
use crate::{
|
||||||
app_signature,
|
app_signature,
|
||||||
dance_info::{CompState, DanceInfo, DanceRank, DanceRole},
|
dance_info::{CompState, DanceInfo, DanceRank, DanceRole},
|
||||||
worldsdc::scoringdance::fetch_wsdc_info_scoring_dance,
|
fetching::DanceInfoError,
|
||||||
};
|
};
|
||||||
use reqwest::ClientBuilder;
|
use reqwest::ClientBuilder;
|
||||||
mod scoringdance;
|
|
||||||
|
|
||||||
pub async fn fetch_wsdc_info_wsdc(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
pub async fn fetch_wsdc_info_wsdc(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||||
let client = ClientBuilder::new()
|
let client = ClientBuilder::new()
|
||||||
@@ -17,7 +16,6 @@ pub async fn fetch_wsdc_info_wsdc(id: u32) -> Result<DanceInfo, DanceInfoError>
|
|||||||
let mut params = HashMap::new();
|
let mut params = HashMap::new();
|
||||||
|
|
||||||
let url = if cfg!(test) {
|
let url = if cfg!(test) {
|
||||||
// "https://o5grQU3Y.free.beeceptor.com/lookup2020/find"
|
|
||||||
"http://localhost:8000"
|
"http://localhost:8000"
|
||||||
} else {
|
} else {
|
||||||
"https://points.worldsdc.com/lookup2020/find"
|
"https://points.worldsdc.com/lookup2020/find"
|
||||||
@@ -37,15 +35,11 @@ pub async fn fetch_wsdc_info_wsdc(id: u32) -> Result<DanceInfo, DanceInfoError>
|
|||||||
Ok(x.into())
|
Ok(x.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
|
||||||
// fetch_wsdc_info_scoring_dance(id).await
|
|
||||||
fetch_wsdc_info_wsdc(id).await
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used, reason = "Allow unwrap in tests")]
|
#![allow(clippy::unwrap_used, reason = "Allow unwrap in tests")]
|
||||||
use crate::worldsdc::fetch_wsdc_info;
|
|
||||||
|
use super::fetch_wsdc_info_wsdc;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore = "Only run when the mock api is setup"]
|
#[ignore = "Only run when the mock api is setup"]
|
||||||
@@ -60,28 +54,14 @@ mod tests {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let x = rt.block_on(fetch_wsdc_info(7));
|
let x = rt.block_on(fetch_wsdc_info_wsdc(7));
|
||||||
dbg!(&x);
|
dbg!(&x);
|
||||||
x.unwrap();
|
x.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
|
||||||
pub enum DanceInfoError {
|
|
||||||
#[error("Failed to build client: {0}")]
|
|
||||||
ClientBuild(reqwest::Error),
|
|
||||||
#[error("Failed to build request: {0}")]
|
|
||||||
RequestBuild(reqwest::Error),
|
|
||||||
#[error("Request error: {0:#?}")]
|
|
||||||
Request(reqwest::Error),
|
|
||||||
#[error("Failed to parse response: {0}")]
|
|
||||||
JsonParse(reqwest::Error),
|
|
||||||
#[error("Failed to parse html: {0}")]
|
|
||||||
HtmlParse(#[from] scoringdance::ScoringParseError),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Debug)]
|
#[derive(serde::Deserialize, Debug)]
|
||||||
enum OptionalDanceRank {
|
pub enum OptionalDanceRank {
|
||||||
#[serde(rename = "N/A")]
|
#[serde(rename = "N/A")]
|
||||||
NotAvailable,
|
NotAvailable,
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
@@ -89,7 +69,7 @@ enum OptionalDanceRank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Debug)]
|
#[derive(serde::Deserialize, Debug)]
|
||||||
enum OptionalDancePoints {
|
pub enum OptionalDancePoints {
|
||||||
#[serde(rename = "N/A")]
|
#[serde(rename = "N/A")]
|
||||||
NotAvailable,
|
NotAvailable,
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
@@ -97,7 +77,7 @@ enum OptionalDancePoints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Debug)]
|
#[derive(serde::Deserialize, Debug)]
|
||||||
struct DanceInfoParser {
|
pub struct DanceInfoParser {
|
||||||
pub dancer_first: String,
|
pub dancer_first: String,
|
||||||
pub dancer_last: String,
|
pub dancer_last: String,
|
||||||
pub short_dominate_role: DanceRole,
|
pub short_dominate_role: DanceRole,
|
||||||
86
src/main.rs
86
src/main.rs
@@ -26,14 +26,15 @@ 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::fetching::{DynWsdcFetcher, ScoringDanceFetcher, WorldsdcFetcher};
|
||||||
use crate::watchdog::{update_wanted_ids, watch_wanted};
|
use crate::watchdog::{update_wanted_ids, watch_wanted};
|
||||||
|
|
||||||
mod dance_info;
|
mod dance_info;
|
||||||
|
mod fetching;
|
||||||
mod updater;
|
mod updater;
|
||||||
mod watchdog;
|
mod watchdog;
|
||||||
mod wikiinfo;
|
mod wikiinfo;
|
||||||
mod wikipage;
|
mod wikipage;
|
||||||
mod worldsdc;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[allow(clippy::print_stdout, reason = "We want to print here")]
|
#[allow(clippy::print_stdout, reason = "We want to print here")]
|
||||||
@@ -107,17 +108,39 @@ fn init_sentry() -> Option<sentry::ClientInitGuard> {
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(name = "myapp")]
|
#[command(name = "teachertracking")]
|
||||||
#[command(about = "A simple CLI app with subcommands", long_about = None)]
|
#[command(about = "MediaWiki Bot to keep West Coast Swing Teacher Scores updated", long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Option<Commands>,
|
command: Option<Commands>,
|
||||||
|
|
||||||
|
#[clap(value_enum)]
|
||||||
|
#[arg(default_value_t)]
|
||||||
|
backend: WsdcPointsBackend,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(clap::ValueEnum, Debug, Clone, Default)]
|
||||||
|
enum WsdcPointsBackend {
|
||||||
|
ScoringDance,
|
||||||
|
#[default]
|
||||||
|
WorldSDC,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
|
/// Continuously watch for missing or outdated teachers and update them
|
||||||
|
Watch,
|
||||||
/// Build pages for all missing teachers
|
/// Build pages for all missing teachers
|
||||||
Missing,
|
FixMissing,
|
||||||
|
/// List all missing teachers
|
||||||
|
ListMissing,
|
||||||
|
/// Update info for all teachers
|
||||||
|
FetchInfo(FetchInfoArgs),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
struct FetchInfoArgs {
|
||||||
|
id: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), AppError> {
|
fn main() -> Result<(), AppError> {
|
||||||
@@ -132,10 +155,17 @@ fn main() -> Result<(), AppError> {
|
|||||||
|
|
||||||
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 {
|
// Build a dynamic fetcher based on CLI selection
|
||||||
Some(Commands::Missing) => {
|
let fetcher: DynWsdcFetcher = match cli.backend {
|
||||||
|
WsdcPointsBackend::ScoringDance => std::sync::Arc::new(ScoringDanceFetcher {}),
|
||||||
|
WsdcPointsBackend::WorldSDC => std::sync::Arc::new(WorldsdcFetcher {}),
|
||||||
|
};
|
||||||
|
let command = cli.command.as_ref().map_or(&Commands::Watch, |cmd| cmd);
|
||||||
|
|
||||||
|
match command {
|
||||||
|
Commands::ListMissing => {
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
let wanted = wikiinfo::wanted_ids(bot.clone()).await;
|
let wanted = wikiinfo::wanted_ids(bot.clone(), fetcher.clone()).await;
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"Missing ids: {}",
|
"Missing ids: {}",
|
||||||
wanted
|
wanted
|
||||||
@@ -145,20 +175,50 @@ fn main() -> Result<(), AppError> {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n")
|
.join("\n")
|
||||||
);
|
);
|
||||||
update_wanted_ids(&wanted, &[]).await;
|
update_wanted_ids(&wanted, &[], fetcher.clone()).await;
|
||||||
});
|
});
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
None => {
|
Commands::FetchInfo(args) => {
|
||||||
|
rt.block_on(async {
|
||||||
|
let info = fetcher.fetch(args.id).await;
|
||||||
|
#[allow(
|
||||||
|
clippy::print_stdout,
|
||||||
|
clippy::print_stderr,
|
||||||
|
reason = "We want to print here"
|
||||||
|
)]
|
||||||
|
match info {
|
||||||
|
Ok(info) => println!("Fetched info: {info:?}"),
|
||||||
|
Err(err) => eprintln!("Error fetching info: {err}"),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Commands::FixMissing => {
|
||||||
|
rt.block_on(async {
|
||||||
|
let wanted = wikiinfo::wanted_ids(bot.clone(), fetcher.clone()).await;
|
||||||
|
tracing::info!(
|
||||||
|
"Missing ids: {}",
|
||||||
|
wanted
|
||||||
|
.iter()
|
||||||
|
.map(|(v, _)| v)
|
||||||
|
.map(u32::to_string)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("\n")
|
||||||
|
);
|
||||||
|
update_wanted_ids(&wanted, &[], fetcher.clone()).await;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Commands::Watch => {
|
||||||
#[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 {
|
rt.block_on(async {
|
||||||
futures::join!(watch_wanted(bot.clone()), updater::update_wsdc(bot))
|
futures::join!(
|
||||||
|
watch_wanted(bot.clone(), fetcher.clone()),
|
||||||
|
updater::update_wsdc(bot, fetcher.clone())
|
||||||
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unreachable!();
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,32 +5,38 @@ use rand::seq::SliceRandom as _;
|
|||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
use crate::{watchdog::generate_page, wikiinfo::index_wsdc_ids};
|
use crate::{watchdog::generate_page, wikiinfo::index_wsdc_ids};
|
||||||
|
use crate::fetching::DynWsdcFetcher;
|
||||||
|
|
||||||
pub async fn update_wsdc(bot: Bot) -> ! {
|
pub async fn update_wsdc(bot: Bot, fetcher: DynWsdcFetcher) -> ! {
|
||||||
loop {
|
loop {
|
||||||
update_all_teachers(&bot).await;
|
update_all_teachers(&bot, fetcher.clone()).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates all teachers once
|
/// Updates all teachers once
|
||||||
async fn update_all_teachers(bot: &Bot) {
|
async fn update_all_teachers(bot: &Bot, fetcher: DynWsdcFetcher) {
|
||||||
let mut l = index_wsdc_ids(bot).await;
|
let mut l = index_wsdc_ids(bot, fetcher.clone()).await;
|
||||||
l.shuffle(&mut rand::rng());
|
l.shuffle(&mut rand::rng());
|
||||||
tracing::info!("We have to update {} pages", l.len());
|
tracing::info!("We have to update {} pages", l.len());
|
||||||
let wait_duration = Duration::from_hours(6);
|
let wait_duration = Duration::from_hours(6);
|
||||||
|
|
||||||
for (index, page) in l {
|
for (index, page) in l {
|
||||||
process_page(wait_duration, index, page).await;
|
process_page(wait_duration, index, page, fetcher.clone()).await;
|
||||||
}
|
}
|
||||||
tracing::info!("Updates all pages");
|
tracing::info!("Updates all pages");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(page, wait_duration))]
|
#[tracing::instrument(skip(page, wait_duration, fetcher))]
|
||||||
async fn process_page(wait_duration: Duration, index: u32, page: mwbot::Page) {
|
async fn process_page(
|
||||||
|
wait_duration: Duration,
|
||||||
|
index: u32,
|
||||||
|
page: mwbot::Page,
|
||||||
|
fetcher: DynWsdcFetcher,
|
||||||
|
) {
|
||||||
tracing::info!("Next up");
|
tracing::info!("Next up");
|
||||||
sleep(wait_duration).await;
|
sleep(wait_duration).await;
|
||||||
|
|
||||||
match generate_page(index, page).await {
|
match generate_page(index, page, fetcher).await {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
tracing::error!("Error updating: {err}");
|
tracing::error!("Error updating: {err}");
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use crate::app_signature;
|
use crate::app_signature;
|
||||||
use crate::wikipage::InfoCompileError;
|
use crate::wikipage::InfoCompileError;
|
||||||
use crate::worldsdc::DanceInfoError;
|
use crate::fetching::types::DanceInfoError;
|
||||||
use crate::{wikiinfo::wanted_ids, wikipage::page_from_info, worldsdc::fetch_wsdc_info};
|
use crate::{wikiinfo::wanted_ids, wikipage::page_from_info};
|
||||||
|
use crate::fetching::DynWsdcFetcher;
|
||||||
use mwbot::SaveOptions;
|
use mwbot::SaveOptions;
|
||||||
use mwbot::{Bot, Page};
|
use mwbot::{Bot, Page};
|
||||||
|
|
||||||
@@ -31,27 +32,31 @@ impl Ticker {
|
|||||||
|
|
||||||
/// Continuously monitors teacher IDs that do not have a corresponding teacher WSDC page, ignoring those that fail processing.
|
/// Continuously monitors teacher IDs that do not have a corresponding teacher WSDC page, ignoring those that fail processing.
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn watch_wanted(bot: Bot) -> ! {
|
pub async fn watch_wanted(bot: Bot, fetcher: DynWsdcFetcher) -> ! {
|
||||||
let mut ignored_ids = vec![];
|
let mut ignored_ids = vec![];
|
||||||
let mut heartbeat_ticker = Ticker::new(120);
|
let mut heartbeat_ticker = Ticker::new(120);
|
||||||
loop {
|
loop {
|
||||||
if heartbeat_ticker.tick() {
|
if heartbeat_ticker.tick() {
|
||||||
tracing::info!(failed_id_count = ignored_ids.len(), "Watchdog check...");
|
tracing::info!(failed_id_count = ignored_ids.len(), "Watchdog check...");
|
||||||
}
|
}
|
||||||
let wanted = wanted_ids(bot.clone()).await;
|
let wanted = wanted_ids(bot.clone(), fetcher.clone()).await;
|
||||||
let new_ignored = update_wanted_ids(&wanted, &ignored_ids).await;
|
let new_ignored = update_wanted_ids(&wanted, &ignored_ids, fetcher.clone()).await;
|
||||||
ignored_ids.extend(new_ignored);
|
ignored_ids.extend(new_ignored);
|
||||||
tokio::time::sleep(Duration::from_secs(30)).await;
|
tokio::time::sleep(Duration::from_secs(30)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub 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],
|
||||||
|
fetcher: DynWsdcFetcher,
|
||||||
|
) -> 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(), fetcher.clone()).await {
|
||||||
tracing::error!("{e}");
|
tracing::error!("{e}");
|
||||||
new_ignored.push(*id);
|
new_ignored.push(*id);
|
||||||
}
|
}
|
||||||
@@ -71,9 +76,13 @@ pub enum GeneratePageError {
|
|||||||
Save(#[from] mwbot::Error),
|
Save(#[from] mwbot::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn generate_page(id: u32, page: mwbot::Page) -> Result<(), GeneratePageError> {
|
pub async fn generate_page(
|
||||||
|
id: u32,
|
||||||
|
page: mwbot::Page,
|
||||||
|
fetcher: DynWsdcFetcher,
|
||||||
|
) -> Result<(), GeneratePageError> {
|
||||||
tracing::info!("Generating page for {id}");
|
tracing::info!("Generating page for {id}");
|
||||||
let info = fetch_wsdc_info(id).await?;
|
let info = fetcher.fetch(id).await?;
|
||||||
|
|
||||||
let code = page_from_info(info)?;
|
let code = page_from_info(info)?;
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ use mwbot::{
|
|||||||
Bot, Page,
|
Bot, Page,
|
||||||
generators::{Generator, querypage::QueryPage, search::Search},
|
generators::{Generator, querypage::QueryPage, search::Search},
|
||||||
};
|
};
|
||||||
|
use crate::fetching::DynWsdcFetcher;
|
||||||
|
|
||||||
pub async fn wanted_ids(bot: Bot) -> Vec<(u32, Page)> {
|
pub async fn wanted_ids(bot: Bot, _fetcher: DynWsdcFetcher) -> Vec<(u32, Page)> {
|
||||||
let mut gene = QueryPage::new("Wantedpages").generate(&bot);
|
let mut gene = QueryPage::new("Wantedpages").generate(&bot);
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
while let Some(x) = gene.recv().await {
|
while let Some(x) = gene.recv().await {
|
||||||
@@ -50,20 +51,8 @@ fn parse_wsdc_page_name(name: &str) -> Result<u32, TitleParseError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn get_wsdc_page_date(bot: &Bot, page: &Page) -> Option<SystemTime> {
|
|
||||||
// todo!();
|
|
||||||
// let prefix = "Updated-On: ";
|
|
||||||
// page.filter_comments()
|
|
||||||
// .iter()
|
|
||||||
// .filter_map(|x| {
|
|
||||||
// let c = x.text_contents();
|
|
||||||
// if c.starts_with(prefix) { Some(c) } else { None }
|
|
||||||
// })
|
|
||||||
// .map(|x| x.trim_start_matches(prefix).parse::<u64>());
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub async fn index_wsdc_ids(bot: &Bot) -> Vec<(u32, Page)> {
|
pub async fn index_wsdc_ids(bot: &Bot, _fetcher: DynWsdcFetcher) -> Vec<(u32, Page)> {
|
||||||
let mut gene = Search::new("WSDC/").generate(bot);
|
let mut gene = Search::new("WSDC/").generate(bot);
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
while let Some(x) = gene.recv().await {
|
while let Some(x) = gene.recv().await {
|
||||||
|
|||||||
Reference in New Issue
Block a user