mirror of
https://codeberg.org/icewind/ugc-scaper.git
synced 2026-06-03 10:14:11 +02:00
handle roster history without steam group
This commit is contained in:
parent
22366e957f
commit
c81cc2f717
5 changed files with 2460 additions and 10 deletions
|
|
@ -172,7 +172,7 @@ pub struct Record {
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct TeamRosterData {
|
pub struct TeamRosterData {
|
||||||
pub steam_group: String,
|
pub steam_group: Option<String>,
|
||||||
pub history: Vec<RosterHistory>,
|
pub history: Vec<RosterHistory>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,16 +49,10 @@ impl Parser for TeamRosterHistoryParser {
|
||||||
fn parse(&self, document: &str) -> Result<Self::Output> {
|
fn parse(&self, document: &str) -> Result<Self::Output> {
|
||||||
let document = Html::parse_document(document);
|
let document = Html::parse_document(document);
|
||||||
|
|
||||||
let steam_group = document.select(&self.selector_steam_group).next().ok_or(
|
let steam_group = document.select(&self.selector_steam_group).next();
|
||||||
ParseError::ElementNotFound {
|
|
||||||
selector: SELECTOR_STEAM,
|
|
||||||
role: "team steam group",
|
|
||||||
},
|
|
||||||
)?;
|
|
||||||
let steam_group = steam_group
|
let steam_group = steam_group
|
||||||
.attr("href")
|
.and_then(|link| link.attr("href"))
|
||||||
.unwrap_or_default()
|
.map(|href| href.replace("http://http", "http"));
|
||||||
.replace("http://http", "http");
|
|
||||||
|
|
||||||
let history = document
|
let history = document
|
||||||
.select(&self.selector_item)
|
.select(&self.selector_item)
|
||||||
|
|
|
||||||
2422
tests/data/team_roster_history_2133.html
Normal file
2422
tests/data/team_roster_history_2133.html
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -36,6 +36,7 @@ fn test_parse_team_html(input: &str, name: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test_case("team_roster_history_7861.html", "team_roster_history")]
|
#[test_case("team_roster_history_7861.html", "team_roster_history")]
|
||||||
|
#[test_case("team_roster_history_2133.html", "team_roster_history_no_group")]
|
||||||
fn test_parse_team_roster_history_html(input: &str, name: &str) {
|
fn test_parse_team_roster_history_html(input: &str, name: &str) {
|
||||||
let body = read_to_string(&format!("tests/data/{input}")).unwrap();
|
let body = read_to_string(&format!("tests/data/{input}")).unwrap();
|
||||||
let parser = TeamRosterHistoryParser::new();
|
let parser = TeamRosterHistoryParser::new();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
---
|
||||||
|
source: tests/snapshot.rs
|
||||||
|
expression: parsed
|
||||||
|
---
|
||||||
|
{
|
||||||
|
"steam_group": null,
|
||||||
|
"history": [
|
||||||
|
{
|
||||||
|
"name": "elwood",
|
||||||
|
"steam_id": "76561197961197074",
|
||||||
|
"joined": "2007-10-04",
|
||||||
|
"left": "2008-01-14"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "crumbles",
|
||||||
|
"steam_id": "76561197963844061",
|
||||||
|
"joined": "2007-10-04",
|
||||||
|
"left": "2008-01-14"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "AO",
|
||||||
|
"steam_id": "76561197960464501",
|
||||||
|
"joined": "2007-10-04",
|
||||||
|
"left": "2008-01-14"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Klone",
|
||||||
|
"steam_id": "76561197961272077",
|
||||||
|
"joined": "2007-10-04",
|
||||||
|
"left": "2008-01-14"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue