This commit is contained in:
@@ -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!("../../test_data/2026-01-07_robert.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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app_signature,
|
app_signature,
|
||||||
dance_info::{CompState, DanceInfo, DanceRank, DanceRole},
|
dance_info::DanceInfo,
|
||||||
fetching::{DanceInfoError, types::DanceInfoParser, scoringdance::{self, fetch_wsdc_info_scoring_dance}},
|
fetching::{DanceInfoError, types::DanceInfoParser},
|
||||||
};
|
};
|
||||||
use reqwest::ClientBuilder;
|
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 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"
|
||||||
|
|||||||
Reference in New Issue
Block a user