mirror of
https://codeberg.org/icewind/ugc-scaper.git
synced 2026-06-03 10:14:11 +02:00
player avatar
This commit is contained in:
parent
1ffdc25582
commit
fcdbc71000
4 changed files with 19 additions and 0 deletions
|
|
@ -43,6 +43,7 @@ mod serde_date {
|
|||
#[non_exhaustive]
|
||||
pub struct Player {
|
||||
pub name: String,
|
||||
pub avatar: String,
|
||||
pub steam_id: SteamID,
|
||||
pub honors: Vec<Honors>,
|
||||
pub teams: Vec<TeamMemberShip>,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ const SELECTOR_PLAYER_TEAM_NAME: &str = "span.text-primary b";
|
|||
const SELECTOR_PLAYER_TEAM_LEAGUE: &str = "small";
|
||||
const SELECTOR_PLAYER_TEAM_SINCE: &str = "small";
|
||||
|
||||
const SELECTOR_AVATAR: &str =
|
||||
r#"a[href*="https://www.ugcleague.com/players_page.cfm?player_id="] img.img-responsive"#;
|
||||
const SELECTOR_CLASS: &str = r#"img.img-rounded[src*="images/tf2/icon/"]"#;
|
||||
|
||||
pub struct PlayerParser {
|
||||
|
|
@ -41,6 +43,7 @@ pub struct PlayerParser {
|
|||
selector_team_league: Selector,
|
||||
selector_team_since: Selector,
|
||||
|
||||
selector_avatar: Selector,
|
||||
selector_class: Selector,
|
||||
}
|
||||
|
||||
|
|
@ -67,6 +70,7 @@ impl PlayerParser {
|
|||
selector_team_league: Selector::parse(SELECTOR_PLAYER_TEAM_LEAGUE).unwrap(),
|
||||
selector_team_since: Selector::parse(SELECTOR_PLAYER_TEAM_SINCE).unwrap(),
|
||||
|
||||
selector_avatar: Selector::parse(SELECTOR_AVATAR).unwrap(),
|
||||
selector_class: Selector::parse(SELECTOR_CLASS).unwrap(),
|
||||
}
|
||||
}
|
||||
|
|
@ -99,6 +103,17 @@ impl Parser for PlayerParser {
|
|||
.unwrap_or_default()
|
||||
.to_string();
|
||||
|
||||
let avatar = document
|
||||
.select(&self.selector_avatar)
|
||||
.next()
|
||||
.ok_or(ParseError::ElementNotFound {
|
||||
selector: SELECTOR_AVATAR,
|
||||
role: "player avatar",
|
||||
})?
|
||||
.attr("src")
|
||||
.unwrap_or_default()
|
||||
.to_string();
|
||||
|
||||
let honors = document
|
||||
.select(&self.selector_honors_group)
|
||||
.flat_map(|group| {
|
||||
|
|
@ -206,6 +221,7 @@ impl Parser for PlayerParser {
|
|||
|
||||
Ok(Player {
|
||||
name,
|
||||
avatar,
|
||||
steam_id: SteamID::from_steam3(&id).unwrap_or_default(),
|
||||
honors,
|
||||
teams,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ expression: parsed
|
|||
---
|
||||
{
|
||||
"name": "Dirty Sneeds Don",
|
||||
"avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/00/00410e6516bc5d5dcc10004c4fa972950e6a5e60_full.jpg",
|
||||
"steam_id": 0,
|
||||
"honors": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ expression: parsed
|
|||
---
|
||||
{
|
||||
"name": "Icewind demostf",
|
||||
"avatar": "https://avatars.akamai.steamstatic.com/75b84075b70535c5cfb3499af03b3e4e7a7b556f_full.jpg",
|
||||
"steam_id": 0,
|
||||
"honors": [
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue