This commit is contained in:
Robin Appelman 2024-11-08 23:09:09 +01:00
commit 5e034d7bef
2 changed files with 6 additions and 17 deletions

View file

@ -55,7 +55,7 @@ impl UgcClient {
pub async fn player(&self, steam_id: SteamID) -> Result<Player> { pub async fn player(&self, steam_id: SteamID) -> Result<Player> {
let res = self let res = self
.client .client
.get(&format!( .get(format!(
"https://www.ugcleague.com/players_page.cfm?player_id={}", "https://www.ugcleague.com/players_page.cfm?player_id={}",
u64::from(steam_id) u64::from(steam_id)
)) ))
@ -72,7 +72,7 @@ impl UgcClient {
pub async fn player_team_history(&self, steam_id: SteamID) -> Result<Vec<MembershipHistory>> { pub async fn player_team_history(&self, steam_id: SteamID) -> Result<Vec<MembershipHistory>> {
let res = self let res = self
.client .client
.get(&format!( .get(format!(
"https://www.ugcleague.com/players_page_details.cfm?player_id={}", "https://www.ugcleague.com/players_page_details.cfm?player_id={}",
u64::from(steam_id) u64::from(steam_id)
)) ))
@ -89,7 +89,7 @@ impl UgcClient {
pub async fn team(&self, id: u32) -> Result<Team> { pub async fn team(&self, id: u32) -> Result<Team> {
let body = self let body = self
.client .client
.get(&format!( .get(format!(
"https://www.ugcleague.com/team_page.cfm?clan_id={}", "https://www.ugcleague.com/team_page.cfm?clan_id={}",
id id
)) ))
@ -104,7 +104,7 @@ impl UgcClient {
pub async fn team_roster_history(&self, id: u32) -> Result<TeamRosterData> { pub async fn team_roster_history(&self, id: u32) -> Result<TeamRosterData> {
let body = self let body = self
.client .client
.get(&format!( .get(format!(
"https://www.ugcleague.com/team_page_rosterhistory.cfm?clan_id={}", "https://www.ugcleague.com/team_page_rosterhistory.cfm?clan_id={}",
id id
)) ))
@ -119,7 +119,7 @@ impl UgcClient {
pub async fn team_matches(&self, id: u32) -> Result<Vec<TeamSeason>> { pub async fn team_matches(&self, id: u32) -> Result<Vec<TeamSeason>> {
let body = self let body = self
.client .client
.get(&format!( .get(format!(
"https://www.ugcleague.com/team_page_matches.cfm?clan_id={}", "https://www.ugcleague.com/team_page_matches.cfm?clan_id={}",
id id
)) ))
@ -155,7 +155,7 @@ impl UgcClient {
pub async fn match_info(&self, id: u32) -> Result<MatchInfo> { pub async fn match_info(&self, id: u32) -> Result<MatchInfo> {
let body = self let body = self
.client .client
.get(&format!( .get(format!(
"https://www.ugcleague.com/matchpage_tf2h.cfm?mid={}", "https://www.ugcleague.com/matchpage_tf2h.cfm?mid={}",
id id
)) ))

View file

@ -33,23 +33,12 @@ pub trait Parser {
trait ElementExt<'a> { trait ElementExt<'a> {
fn first_text(&self) -> Option<&'a str>; fn first_text(&self) -> Option<&'a str>;
fn nth_text(&self, n: usize) -> Option<&'a str>;
fn last_text(&self) -> Option<&'a str>;
} }
impl<'a> ElementExt<'a> for ElementRef<'a> { impl<'a> ElementExt<'a> for ElementRef<'a> {
fn first_text(&self) -> Option<&'a str> { fn first_text(&self) -> Option<&'a str> {
self.text().map(str::trim).find(|s| !s.is_empty()) self.text().map(str::trim).find(|s| !s.is_empty())
} }
fn nth_text(&self, n: usize) -> Option<&'a str> {
self.text()
.filter(|s| !s.trim().is_empty())
.nth(n - 1)
.map(str::trim)
}
fn last_text(&self) -> Option<&'a str> {
self.text().map(str::trim).filter(|s| !s.is_empty()).last()
}
} }
fn select_text<'a>(el: ElementRef<'a>, selector: &Selector) -> Option<&'a str> { fn select_text<'a>(el: ElementRef<'a>, selector: &Selector) -> Option<&'a str> {