mirror of
https://codeberg.org/icewind/ugc-scaper.git
synced 2026-06-03 10:14:11 +02:00
extract region
This commit is contained in:
parent
98b690356c
commit
8fd98b708f
5 changed files with 51 additions and 1 deletions
|
|
@ -5,8 +5,9 @@ use crate::parser::{
|
|||
};
|
||||
use crate::{ParseError, Result, ScrapeError};
|
||||
use scraper::{Html, Selector};
|
||||
use std::str::FromStr;
|
||||
use time::{Date, PrimitiveDateTime, Time, UtcOffset};
|
||||
use ugc_scraper_types::GameMode;
|
||||
use ugc_scraper_types::{GameMode, Region};
|
||||
|
||||
const SELECTOR_TEAM_NAME: &str = ".container .col-md-12 h1 > b";
|
||||
const SELECTOR_TEAM_TAG: &str = ".container .col-md-12 h1 > span";
|
||||
|
|
@ -171,6 +172,14 @@ impl Parser for TeamParser {
|
|||
})?
|
||||
.to_string();
|
||||
|
||||
let region = division
|
||||
.split(' ')
|
||||
.find_map(|part| Region::from_str(part).ok())
|
||||
.ok_or_else(|| ParseError::InvalidText {
|
||||
text: division.clone(),
|
||||
role: "team region",
|
||||
})?;
|
||||
|
||||
let timezone = select_text(root, &self.selector_team_timezone).map(String::from);
|
||||
|
||||
let description = select_text(root, &self.selector_team_description)
|
||||
|
|
@ -354,6 +363,7 @@ impl Parser for TeamParser {
|
|||
results,
|
||||
members,
|
||||
name_changes,
|
||||
region,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ expression: parsed
|
|||
"tag": "Melting Pot",
|
||||
"image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/f7/f75809d7774c917be9883370d772d3099bfe457d_full.jpg",
|
||||
"format": "9v9",
|
||||
"region": "Euro",
|
||||
"timezone": "West-Euro",
|
||||
"steam_group": "http://steamcommunity.com/groups/Melintongpotsss",
|
||||
"division": "Euro Platinum",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ expression: parsed
|
|||
"tag": "-Xe-",
|
||||
"image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/db/dbabbd8bab7ccf6d27a9d4ca2e73a76e085bb201_full.jpg",
|
||||
"format": "9v9",
|
||||
"region": "Euro",
|
||||
"timezone": "West-Euro",
|
||||
"steam_group": "https://steamcommunity.com/groups/XenonxTF2",
|
||||
"division": "Euro Platinum",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ expression: parsed
|
|||
"tag": "Grand Meister",
|
||||
"image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d7/d71ff4e1e2635c3d7c1be8d96bc40b499c665aad_full.jpg",
|
||||
"format": "9v9",
|
||||
"region": "NorthAmerica",
|
||||
"timezone": null,
|
||||
"steam_group": "http://steamcommunity.com/groups/BARNEYANDTHEGANKS",
|
||||
"division": "NA Platinum",
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ pub struct Team {
|
|||
pub tag: String,
|
||||
pub image: String,
|
||||
pub format: GameMode,
|
||||
pub region: Region,
|
||||
pub timezone: Option<String>,
|
||||
pub steam_group: Option<String>,
|
||||
pub division: String,
|
||||
|
|
@ -350,6 +351,42 @@ impl Display for GameMode {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Error)]
|
||||
#[error("Invalid team region: {text}")]
|
||||
pub struct InvalidRegion {
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
|
||||
pub enum Region {
|
||||
Euro,
|
||||
NorthAmerica,
|
||||
SouthAmerica,
|
||||
Asia,
|
||||
Australia,
|
||||
}
|
||||
|
||||
impl FromStr for Region {
|
||||
type Err = InvalidRegion;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"Euro" => Ok(Region::Euro),
|
||||
"EU" => Ok(Region::Euro),
|
||||
"Asia" => Ok(Region::Asia),
|
||||
"ASIA" => Ok(Region::Asia),
|
||||
"NA" => Ok(Region::NorthAmerica),
|
||||
"South American" => Ok(Region::SouthAmerica),
|
||||
"SA" => Ok(Region::SouthAmerica),
|
||||
"AUS" => Ok(Region::Australia),
|
||||
"AUS/NZ" => Ok(Region::Australia),
|
||||
_ => Err(InvalidRegion {
|
||||
text: s.to_string(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct Transaction {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue