improve not found team detection

This commit is contained in:
Robin Appelman 2025-04-21 16:39:01 +02:00
commit cf8de44bbb
7 changed files with 42 additions and 29 deletions

View file

@ -228,6 +228,7 @@ async fn archive_map_history(client: &UgcClient, archive: &Archive, mode: GameMo
async fn fixup_matches(client: &UgcClient, archive: &Archive) -> MainResult { async fn fixup_matches(client: &UgcClient, archive: &Archive) -> MainResult {
let min_team = archive.get_min_team_id_without_match_seasons().await?; let min_team = archive.get_min_team_id_without_match_seasons().await?;
dbg!(min_team);
let mut team_ids = pin!(archive.get_team_ids(min_team - 1)); let mut team_ids = pin!(archive.get_team_ids(min_team - 1));
while let Some(Ok(team_id)) = team_ids.next().await { while let Some(Ok(team_id)) = team_ids.next().await {

View file

@ -6,7 +6,7 @@ use scraper::{Html, Selector};
const SELECTOR_MATCH_FORMAT: &str = "h3.page-header > strong.styleColor"; const SELECTOR_MATCH_FORMAT: &str = "h3.page-header > strong.styleColor";
const SELECTOR_MATCH_COMMENT_AUTHOR: &str = ".row-fluid .col-md-12 span.text-success"; const SELECTOR_MATCH_COMMENT_AUTHOR: &str = ".row-fluid .col-md-12 span.text-success";
const SELECTOR_MATCH_COMMENT: &str = ".row-fluid .col-md-12 > .white-row-light-small > p"; const SELECTOR_MATCH_COMMENT: &str = ".row-fluid .col-md-12 > .text-center > p";
const SELECTOR_MATCH_TEAM_LINK: &str = "a[href^=\"team_page\"]:not(.btn-large)"; const SELECTOR_MATCH_TEAM_LINK: &str = "a[href^=\"team_page\"]:not(.btn-large)";
const SELECTOR_MATCH_RESULT_TEAM: &str = const SELECTOR_MATCH_RESULT_TEAM: &str =
".table.table-condensed.table-bordered tr:nth-child(2) td:nth-child(1)"; ".table.table-condensed.table-bordered tr:nth-child(2) td:nth-child(1)";
@ -119,10 +119,7 @@ impl Parser for MatchPageParser {
role: "home team link", role: "home team link",
})? })?
.first_text() .first_text()
.ok_or(ParseError::EmptyText { .unwrap_or_default()
role: "home team name",
selector: SELECTOR_MATCH_RESULT_TEAM,
})?
.to_string(); .to_string();
let team_name_away = team_names let team_name_away = team_names
.next() .next()
@ -131,10 +128,7 @@ impl Parser for MatchPageParser {
role: "away team link", role: "away team link",
})? })?
.first_text() .first_text()
.ok_or(ParseError::EmptyText { .unwrap_or_default()
role: "away team name",
selector: SELECTOR_MATCH_RESULT_TEAM,
})?
.to_string(); .to_string();
let mut team_scores = document.select(&self.selector_result_score); let mut team_scores = document.select(&self.selector_result_score);

View file

@ -132,13 +132,14 @@ impl Parser for TeamParser {
.unwrap_or_default() .unwrap_or_default()
.to_string(); .to_string();
match (tag.as_str(), name.as_str()) { let image = document.select(&self.selector_image).next();
("", "") => return Err(ScrapeError::NotFound),
(_, "") => name = tag.clone(), match (tag.as_str(), name.as_str(), image.is_some()) {
("", "", false) => return Err(ScrapeError::NotFound),
(_, "", true) => name = tag.clone(),
_ => {} _ => {}
}; };
let image = document.select(&self.selector_image).next();
let image = image.and_then(|image| { let image = image.and_then(|image| {
image image
.attr("data-cfsrc") .attr("data-cfsrc")

View file

@ -267,12 +267,8 @@ impl Parser for TeamMatchesParser {
role: "match team link", role: "match team link",
})?; })?;
let team_name = select_text(document.root_element(), &self.selector_team_name).ok_or( let team_name =
ParseError::ElementNotFound { select_text(document.root_element(), &self.selector_team_name).unwrap_or_default();
selector: SELECTOR_TEAM_NAME,
role: "match team name",
},
)?;
let team = TeamRef { let team = TeamRef {
id: team_id, id: team_id,
name: team_name.into(), name: team_name.into(),

View file

@ -3,7 +3,7 @@ source: tests/snapshot.rs
expression: parsed expression: parsed
--- ---
{ {
"comment": "https://logs.tf/3509421#76561198288857894\r\nhttps://logs.tf/3509435#76561198288857894", "comment": null,
"comment_author": "Vkid E-sports:", "comment_author": "Vkid E-sports:",
"team_home": { "team_home": {
"name": "Vkid E-Sports", "name": "Vkid E-Sports",

View file

@ -22,7 +22,9 @@ expression: parsed
"opponent": { "opponent": {
"name": "[$0.00]", "name": "[$0.00]",
"id": 2137 "id": 2137
} },
"score": 0,
"score_opponent": 0
}, },
"map": "cp_gravelpit" "map": "cp_gravelpit"
}, },
@ -36,7 +38,9 @@ expression: parsed
"opponent": { "opponent": {
"name": "-DeX-", "name": "-DeX-",
"id": 2130 "id": 2130
} },
"score": 0,
"score_opponent": 0
}, },
"map": "cp_gravelpit" "map": "cp_gravelpit"
}, },
@ -50,7 +54,9 @@ expression: parsed
"opponent": { "opponent": {
"name": "[UGS]", "name": "[UGS]",
"id": 2127 "id": 2127
} },
"score": 3,
"score_opponent": 0
}, },
"map": "cp_dustbowl" "map": "cp_dustbowl"
}, },
@ -74,7 +80,9 @@ expression: parsed
"opponent": { "opponent": {
"name": ".tKd", "name": ".tKd",
"id": 2169 "id": 2169
} },
"score": 0,
"score_opponent": 0
}, },
"map": "ctf_impact" "map": "ctf_impact"
}, },
@ -88,7 +96,9 @@ expression: parsed
"opponent": { "opponent": {
"name": "[FOoM]", "name": "[FOoM]",
"id": 2172 "id": 2172
} },
"score": 0,
"score_opponent": 0
}, },
"map": "cp_science2" "map": "cp_science2"
}, },
@ -102,7 +112,9 @@ expression: parsed
"opponent": { "opponent": {
"name": "[SWAT]", "name": "[SWAT]",
"id": 2188 "id": 2188
} },
"score": 1,
"score_opponent": 0
}, },
"map": "cp_junction" "map": "cp_junction"
}, },
@ -116,7 +128,9 @@ expression: parsed
"opponent": { "opponent": {
"name": "[FOoM]", "name": "[FOoM]",
"id": 2172 "id": 2172
} },
"score": 0,
"score_opponent": 0
}, },
"map": "cp_castle3" "map": "cp_castle3"
}, },
@ -130,7 +144,9 @@ expression: parsed
"opponent": { "opponent": {
"name": "[=1=]", "name": "[=1=]",
"id": 2197 "id": 2197
} },
"score": 0,
"score_opponent": 0
}, },
"map": "cp_dustbowl" "map": "cp_dustbowl"
}, },
@ -144,7 +160,9 @@ expression: parsed
"opponent": { "opponent": {
"name": "[FOoM]", "name": "[FOoM]",
"id": 2172 "id": 2172
} },
"score": 0,
"score_opponent": 0
}, },
"map": "cp_science" "map": "cp_science"
} }

View file

@ -466,14 +466,17 @@ impl FromStr for GameMode {
"1v1" => Ok(GameMode::Ones), "1v1" => Ok(GameMode::Ones),
"Highlander" => Ok(GameMode::Highlander), "Highlander" => Ok(GameMode::Highlander),
"TF2 Highlander" => Ok(GameMode::Highlander), "TF2 Highlander" => Ok(GameMode::Highlander),
"TF2-H" => Ok(GameMode::Highlander),
"ASIA TF2-H" => Ok(GameMode::Highlander), "ASIA TF2-H" => Ok(GameMode::Highlander),
"ASIA TF2-6" => Ok(GameMode::Sixes), "ASIA TF2-6" => Ok(GameMode::Sixes),
"ASIA TF2-4" => Ok(GameMode::Fours), "ASIA TF2-4" => Ok(GameMode::Fours),
"TF2 8vs8" => Ok(GameMode::Eights), "TF2 8vs8" => Ok(GameMode::Eights),
"8vs8" => Ok(GameMode::Eights), "8vs8" => Ok(GameMode::Eights),
"TF2 6vs6" => Ok(GameMode::Sixes), "TF2 6vs6" => Ok(GameMode::Sixes),
"TF2-6" => Ok(GameMode::Sixes),
"6vs6" => Ok(GameMode::Sixes), "6vs6" => Ok(GameMode::Sixes),
"TF2 4vs4" => Ok(GameMode::Fours), "TF2 4vs4" => Ok(GameMode::Fours),
"TF2-4" => Ok(GameMode::Fours),
"4vs4" => Ok(GameMode::Fours), "4vs4" => Ok(GameMode::Fours),
"TF2 2vs2" => Ok(GameMode::Ultiduo), "TF2 2vs2" => Ok(GameMode::Ultiduo),
"2vs2" => Ok(GameMode::Ultiduo), "2vs2" => Ok(GameMode::Ultiduo),