Compare commits
11 Commits
html_scrap
...
46dc757bb7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46dc757bb7 | ||
|
|
b869842aa3 | ||
|
|
a2642f6b9a | ||
|
|
3d66841e74 | ||
|
|
0d88629b17 | ||
|
|
681cc0f59d | ||
|
|
7baff3a50c | ||
|
|
31293d1807 | ||
|
|
5414a1bb26 | ||
|
|
c45001cb6d | ||
|
|
5fae51248a |
30
.gitea/workflows/release.yaml
Normal file
30
.gitea/workflows/release.yaml
Normal file
@@ -0,0 +1,30 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
|
||||
env:
|
||||
RUSTUP_TOOLCHAIN: nightly
|
||||
|
||||
jobs:
|
||||
build_release:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITEA_SERVER: ${{ secrets.GITEA_SERVER }}
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
|
||||
- name: Build release
|
||||
run: |
|
||||
cargo build --release
|
||||
- uses: akkuman/gitea-release-action@v1
|
||||
with:
|
||||
files: |-
|
||||
target/release/teachertracker-rs
|
||||
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
|
||||
2125
Cargo.lock
generated
2125
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "teachertracker-rs"
|
||||
version = "0.1.3"
|
||||
version = "0.1.5"
|
||||
edition = "2024"
|
||||
authors = ["Lukas Wölfer <coding@thasky.one>"]
|
||||
description = "A MediaWiki bot that updates score information of teachers"
|
||||
@@ -12,15 +12,19 @@ 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"
|
||||
tokio = { version = "1.46.1", features = ["rt"] }
|
||||
tracing = { version = "0.1.41", default-features = false, features = ["std"] }
|
||||
tracing-subscriber = "0.3.19"
|
||||
async-trait = "0.1.79"
|
||||
|
||||
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
|
||||
@@ -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,
|
||||
|
||||
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::{
|
||||
app_signature,
|
||||
dance_info::{CompState, DanceInfo, DanceRank, DanceRole},
|
||||
worldsdc::DanceInfoError,
|
||||
fetching::DanceInfoError,
|
||||
};
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum ScoringParseError {
|
||||
@@ -135,14 +135,11 @@ fn parse_stats(
|
||||
rank: *rank,
|
||||
});
|
||||
Ok((primary_role, dominant_comp, non_dominant_comp))
|
||||
|
||||
// dbg!(chapters.collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
fn extract_tables(html: &str) -> Result<Vec<(String, Vec<Vec<String>>)>, ScoringParseError> {
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -171,11 +168,6 @@ fn parse_info(html: &str) -> Result<DanceInfo, ScoringParseError> {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_table() {
|
||||
dbg!(parse_info(include_str!("../../polina.html")));
|
||||
}
|
||||
|
||||
pub async fn fetch_wsdc_info_scoring_dance(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||
let client = ClientBuilder::new()
|
||||
.user_agent(app_signature())
|
||||
@@ -194,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)
|
||||
}
|
||||
|
||||
#[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::{
|
||||
app_signature,
|
||||
dance_info::{CompState, DanceInfo, DanceRank, DanceRole},
|
||||
worldsdc::scoringdance::fetch_wsdc_info_scoring_dance,
|
||||
fetching::DanceInfoError,
|
||||
};
|
||||
use reqwest::ClientBuilder;
|
||||
mod scoringdance;
|
||||
|
||||
pub async fn fetch_wsdc_info_wsdc(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||
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 url = if cfg!(test) {
|
||||
// "https://o5grQU3Y.free.beeceptor.com/lookup2020/find"
|
||||
"http://localhost:8000"
|
||||
} else {
|
||||
"https://points.worldsdc.com/lookup2020/find"
|
||||
@@ -37,14 +35,11 @@ pub async fn fetch_wsdc_info_wsdc(id: u32) -> Result<DanceInfo, DanceInfoError>
|
||||
Ok(x.into())
|
||||
}
|
||||
|
||||
pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||
fetch_wsdc_info_scoring_dance(id).await
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used, reason = "Allow unwrap in tests")]
|
||||
use crate::worldsdc::fetch_wsdc_info;
|
||||
|
||||
use super::fetch_wsdc_info_wsdc;
|
||||
|
||||
#[test]
|
||||
#[ignore = "Only run when the mock api is setup"]
|
||||
@@ -59,28 +54,14 @@ mod tests {
|
||||
return;
|
||||
}
|
||||
};
|
||||
let x = rt.block_on(fetch_wsdc_info(7));
|
||||
let x = rt.block_on(fetch_wsdc_info_wsdc(7));
|
||||
dbg!(&x);
|
||||
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)]
|
||||
enum OptionalDanceRank {
|
||||
pub enum OptionalDanceRank {
|
||||
#[serde(rename = "N/A")]
|
||||
NotAvailable,
|
||||
#[serde(untagged)]
|
||||
@@ -88,7 +69,7 @@ enum OptionalDanceRank {
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug)]
|
||||
enum OptionalDancePoints {
|
||||
pub enum OptionalDancePoints {
|
||||
#[serde(rename = "N/A")]
|
||||
NotAvailable,
|
||||
#[serde(untagged)]
|
||||
@@ -96,7 +77,7 @@ enum OptionalDancePoints {
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug)]
|
||||
struct DanceInfoParser {
|
||||
pub struct DanceInfoParser {
|
||||
pub dancer_first: String,
|
||||
pub dancer_last: String,
|
||||
pub short_dominate_role: DanceRole,
|
||||
129
src/main.rs
129
src/main.rs
@@ -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,15 +23,18 @@ 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};
|
||||
use crate::fetching::{DynWsdcFetcher, WorldsdcFetcher, ScoringDanceFetcher};
|
||||
|
||||
mod dance_info;
|
||||
mod fetching;
|
||||
mod updater;
|
||||
mod watchdog;
|
||||
mod wikiinfo;
|
||||
mod wikipage;
|
||||
mod worldsdc;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[allow(clippy::print_stdout, reason = "We want to print here")]
|
||||
@@ -60,24 +62,121 @@ 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 = "teachertracking")]
|
||||
#[command(about = "MediaWiki Bot to keep West Coast Swing Teacher Scores updated", long_about = None)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
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)]
|
||||
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)) });
|
||||
// Build a dynamic fetcher based on CLI selection
|
||||
let fetcher: DynWsdcFetcher = match cli.backend {
|
||||
WsdcPointsBackend::ScoringDance => std::sync::Arc::new(ScoringDanceFetcher {}),
|
||||
WsdcPointsBackend::WorldSDC => std::sync::Arc::new(WorldsdcFetcher {}),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
match &cli.command {
|
||||
Some(Commands::Missing) => {
|
||||
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;
|
||||
});
|
||||
|
||||
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(), fetcher.clone()), updater::update_wsdc(bot, fetcher.clone()))
|
||||
});
|
||||
}
|
||||
}
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
@@ -5,32 +5,38 @@ use rand::seq::SliceRandom as _;
|
||||
use tokio::time::sleep;
|
||||
|
||||
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 {
|
||||
update_all_teachers(&bot).await;
|
||||
update_all_teachers(&bot, fetcher.clone()).await;
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates all teachers once
|
||||
async fn update_all_teachers(bot: &Bot) {
|
||||
let mut l = index_wsdc_ids(bot).await;
|
||||
async fn update_all_teachers(bot: &Bot, fetcher: DynWsdcFetcher) {
|
||||
let mut l = index_wsdc_ids(bot, fetcher.clone()).await;
|
||||
l.shuffle(&mut rand::rng());
|
||||
tracing::info!("We have to update {} pages", l.len());
|
||||
let wait_duration = Duration::from_hours(6);
|
||||
|
||||
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::instrument(skip(page, wait_duration))]
|
||||
async fn process_page(wait_duration: Duration, index: u32, page: mwbot::Page) {
|
||||
#[tracing::instrument(skip(page, wait_duration, fetcher))]
|
||||
async fn process_page(
|
||||
wait_duration: Duration,
|
||||
index: u32,
|
||||
page: mwbot::Page,
|
||||
fetcher: DynWsdcFetcher,
|
||||
) {
|
||||
tracing::info!("Next up");
|
||||
sleep(wait_duration).await;
|
||||
|
||||
match generate_page(index, page).await {
|
||||
match generate_page(index, page, fetcher).await {
|
||||
Ok(()) => (),
|
||||
Err(err) => {
|
||||
tracing::error!("Error updating: {err}");
|
||||
|
||||
@@ -2,8 +2,9 @@ use std::time::Duration;
|
||||
|
||||
use crate::app_signature;
|
||||
use crate::wikipage::InfoCompileError;
|
||||
use crate::worldsdc::DanceInfoError;
|
||||
use crate::{wikiinfo::wanted_ids, wikipage::page_from_info, worldsdc::fetch_wsdc_info};
|
||||
use crate::fetching::types::DanceInfoError;
|
||||
use crate::{wikiinfo::wanted_ids, wikipage::page_from_info};
|
||||
use crate::fetching::DynWsdcFetcher;
|
||||
use mwbot::SaveOptions;
|
||||
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.
|
||||
#[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 heartbeat_ticker = Ticker::new(120);
|
||||
loop {
|
||||
if heartbeat_ticker.tick() {
|
||||
tracing::info!(failed_id_count = ignored_ids.len(), "Watchdog check...");
|
||||
}
|
||||
let wanted = wanted_ids(bot.clone()).await;
|
||||
let new_ignored = update_wanted_ids(&wanted, &ignored_ids).await;
|
||||
let wanted = wanted_ids(bot.clone(), fetcher.clone()).await;
|
||||
let new_ignored = update_wanted_ids(&wanted, &ignored_ids, fetcher.clone()).await;
|
||||
ignored_ids.extend(new_ignored);
|
||||
tokio::time::sleep(Duration::from_secs(30)).await;
|
||||
}
|
||||
}
|
||||
|
||||
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![];
|
||||
|
||||
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 {
|
||||
if let Err(e) = generate_page(*id, page.clone(), fetcher.clone()).await {
|
||||
tracing::error!("{e}");
|
||||
new_ignored.push(*id);
|
||||
}
|
||||
@@ -71,9 +76,13 @@ pub enum GeneratePageError {
|
||||
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}");
|
||||
let info = fetch_wsdc_info(id).await?;
|
||||
let info = fetcher.fetch(id).await?;
|
||||
|
||||
let code = page_from_info(info)?;
|
||||
|
||||
|
||||
@@ -2,15 +2,24 @@ use mwbot::{
|
||||
Bot, Page,
|
||||
generators::{Generator, querypage::QueryPage, search::Search},
|
||||
};
|
||||
use crate::fetching::DynWsdcFetcher;
|
||||
|
||||
pub async fn wanted_ids(bot: Bot) -> Vec<(u32, Page)> {
|
||||
let mut gene = QueryPage::new("Wantedpages").generate(&bot);
|
||||
pub async fn wanted_ids(_bot: Bot, _fetcher: DynWsdcFetcher) -> Vec<(u32, Page)> {
|
||||
let mut gene = QueryPage::new("Wantedpages").generate(&_bot);
|
||||
let mut result = vec![];
|
||||
while let Some(x) = gene.recv().await {
|
||||
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;
|
||||
}
|
||||
};
|
||||
@@ -55,7 +64,7 @@ fn parse_wsdc_page_name(name: &str) -> Result<u32, TitleParseError> {
|
||||
// }
|
||||
|
||||
#[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 result = vec![];
|
||||
while let Some(x) = gene.recv().await {
|
||||
|
||||
1
test_data/2026-01-07_robert.html
Normal file
1
test_data/2026-01-07_robert.html
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user