mirror of
https://codeberg.org/icewind/ugc-scaper.git
synced 2026-06-03 10:14:11 +02:00
improved region parsing
This commit is contained in:
parent
444482d57a
commit
2c6264ccf0
5 changed files with 3774 additions and 0 deletions
|
|
@ -180,6 +180,7 @@ impl Parser for TeamParser {
|
|||
let region = division
|
||||
.split(' ')
|
||||
.find_map(|part| Region::from_str(part).ok())
|
||||
.or_else(|| Region::from_str(division.trim_end_matches("New Teams").trim()).ok())
|
||||
.or_else(|| Region::from_str(&division).ok());
|
||||
|
||||
let timezone = select_text(root, &self.selector_team_timezone).map(String::from);
|
||||
|
|
|
|||
3704
tests/data/team_11789.html
Normal file
3704
tests/data/team_11789.html
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -40,6 +40,7 @@ fn test_parse_player_details_html(input: &str, name: &str) {
|
|||
#[test_case("team_3975.html", "team_empty_player")]
|
||||
#[test_case("team_2909.html", "team_1v1_sol")]
|
||||
#[test_case("team_5058.html", "team_empty_name_change2")]
|
||||
#[test_case("team_11789.html", "team_space_region")]
|
||||
#[cfg(feature = "serde")]
|
||||
fn test_parse_team_html(input: &str, name: &str) {
|
||||
let body = read_to_string(format!("tests/data/{input}")).unwrap();
|
||||
|
|
|
|||
56
tests/snapshots/snapshot__parse_team_space_region_html.snap
Normal file
56
tests/snapshots/snapshot__parse_team_space_region_html.snap
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
---
|
||||
source: tests/snapshot.rs
|
||||
expression: parsed
|
||||
---
|
||||
{
|
||||
"name": "Potato Game Sense",
|
||||
"tag": "pgs",
|
||||
"image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/41/41d8336613741e77adfe57ccf747abad9e1209ce_full.jpg",
|
||||
"format": "9v9",
|
||||
"region": "south-america",
|
||||
"timezone": "SA-East",
|
||||
"steam_group": "http://steamcommunity.com/groups/potatogshl",
|
||||
"division": "*S. America New Teams",
|
||||
"description": "Batata",
|
||||
"titles": [],
|
||||
"members": [
|
||||
{
|
||||
"name": "boomer",
|
||||
"steam_id": "76561198068200396",
|
||||
"role": "leader",
|
||||
"since": "+002014-05-13T00:00:00.000000000Z"
|
||||
},
|
||||
{
|
||||
"name": "Angra",
|
||||
"steam_id": "76561198049967350",
|
||||
"role": "member",
|
||||
"since": "+002014-05-13T00:00:00.000000000Z"
|
||||
},
|
||||
{
|
||||
"name": "jota",
|
||||
"steam_id": "76561198044420376",
|
||||
"role": "member",
|
||||
"since": "+002014-05-14T00:00:00.000000000Z"
|
||||
},
|
||||
{
|
||||
"name": "ap Kiyoshi",
|
||||
"steam_id": "76561198057649052",
|
||||
"role": "member",
|
||||
"since": "+002014-05-14T00:00:00.000000000Z"
|
||||
},
|
||||
{
|
||||
"name": "darondrunk",
|
||||
"steam_id": "76561198050145901",
|
||||
"role": "member",
|
||||
"since": "+002014-05-14T00:00:00.000000000Z"
|
||||
},
|
||||
{
|
||||
"name": "Jacksideh",
|
||||
"steam_id": "76561198045916617",
|
||||
"role": "member",
|
||||
"since": "+002014-05-14T00:00:00.000000000Z"
|
||||
}
|
||||
],
|
||||
"results": [],
|
||||
"name_changes": []
|
||||
}
|
||||
|
|
@ -450,19 +450,31 @@ impl FromStr for Region {
|
|||
type Err = InvalidRegion;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let s = s.trim_matches(&['*', '(', ')']);
|
||||
match s {
|
||||
"Euro" => Ok(Region::Europe),
|
||||
"Europe" => Ok(Region::Europe),
|
||||
"European" => Ok(Region::Europe),
|
||||
"EU" => Ok(Region::Europe),
|
||||
"E.U." => Ok(Region::Europe),
|
||||
"Asia" => Ok(Region::Asia),
|
||||
"ASIA" => Ok(Region::Asia),
|
||||
"NA" => Ok(Region::NorthAmerica),
|
||||
"N.A." => Ok(Region::NorthAmerica),
|
||||
"North America" => Ok(Region::NorthAmerica),
|
||||
"N.America" => Ok(Region::NorthAmerica),
|
||||
"N. America" => Ok(Region::NorthAmerica),
|
||||
"N.Amer" => Ok(Region::NorthAmerica),
|
||||
"S.Amer" => Ok(Region::SouthAmerica),
|
||||
"South American" => Ok(Region::SouthAmerica),
|
||||
"South America" => Ok(Region::SouthAmerica),
|
||||
"S.America" => Ok(Region::SouthAmerica),
|
||||
"S. America" => Ok(Region::SouthAmerica),
|
||||
"SA" => Ok(Region::SouthAmerica),
|
||||
"S.A." => Ok(Region::SouthAmerica),
|
||||
"AUS" => Ok(Region::Australia),
|
||||
"AUS/NZ" => Ok(Region::Australia),
|
||||
"AUS-NZ" => Ok(Region::Australia),
|
||||
_ => Err(InvalidRegion {
|
||||
text: s.to_string(),
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue