This commit is contained in:
@@ -135,26 +135,16 @@ 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> {
|
||||
dbg!(&html);
|
||||
let document = Html::parse_document(html);
|
||||
let card_selector = Selector::parse("div:has( > div.card-header)").unwrap();
|
||||
document
|
||||
.select(&card_selector)
|
||||
.inspect(|v| {
|
||||
dbg!(&v);
|
||||
})
|
||||
.map(parse_card)
|
||||
.collect()
|
||||
document.select(&card_selector).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"))
|
||||
@@ -178,11 +168,6 @@ fn parse_info(html: &str) -> Result<DanceInfo, ScoringParseError> {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_table() {
|
||||
dbg!(parse_info(include_str!("../../test_data/2026-01-07_robert.html")));
|
||||
}
|
||||
|
||||
pub async fn fetch_wsdc_info_scoring_dance(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||
let client = ClientBuilder::new()
|
||||
.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)
|
||||
}
|
||||
|
||||
#[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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
app_signature,
|
||||
dance_info::{CompState, DanceInfo, DanceRank, DanceRole},
|
||||
fetching::{DanceInfoError, types::DanceInfoParser, scoringdance::{self, fetch_wsdc_info_scoring_dance}},
|
||||
dance_info::DanceInfo,
|
||||
fetching::{DanceInfoError, types::DanceInfoParser},
|
||||
};
|
||||
use reqwest::ClientBuilder;
|
||||
|
||||
@@ -16,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"
|
||||
|
||||
Reference in New Issue
Block a user