map history api

This commit is contained in:
Robin Appelman 2023-11-21 20:24:01 +01:00
commit 6eec064496
8 changed files with 30 additions and 10 deletions

2
Cargo.lock generated
View file

@ -1540,7 +1540,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]] [[package]]
name = "ugc-scraper" name = "ugc-scraper"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"insta", "insta",
"main_error", "main_error",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ugc-scraper" name = "ugc-scraper"
version = "0.2.0" version = "0.2.1"
edition = "2021" edition = "2021"
rust-version = "1.67.0" rust-version = "1.67.0"
description = "Scraper for ugcleague.com" description = "Scraper for ugcleague.com"

4
api-server/Cargo.lock generated
View file

@ -1742,9 +1742,7 @@ dependencies = [
[[package]] [[package]]
name = "ugc-scraper" name = "ugc-scraper"
version = "0.2.0" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3be88e517d2c0e368dc65c377c9fd60583fb430ab4fe5bc7b348120e0e9df42f"
dependencies = [ dependencies = [
"reqwest", "reqwest",
"scraper", "scraper",

View file

@ -6,8 +6,8 @@ edition = "2021"
[dependencies] [dependencies]
tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread", "rt"] } tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread", "rt"] }
main_error = "0.1.2" main_error = "0.1.2"
#ugc-scraper = { path = "../", version = "0.2.0" } ugc-scraper = { path = "../", version = "0.2.1" }
ugc-scraper = "0.2.0" #ugc-scraper = "0.2.1"
axum = "0.6.20" axum = "0.6.20"
steamid-ng = "1.0.0" steamid-ng = "1.0.0"
thiserror = "1.0.50" thiserror = "1.0.50"

View file

@ -35,3 +35,7 @@ Get team match history
### `match/:id` ### `match/:id`
Get match information Get match information
### `/maps/:format`
Get map history by format (`9v9`, `6v6`, `4v4`, `2v2`)

View file

@ -68,6 +68,7 @@ async fn main() -> MainResult {
.route("/team/:id/roster", get(team_roster)) .route("/team/:id/roster", get(team_roster))
.route("/team/:id/matches", get(team_matches)) .route("/team/:id/matches", get(team_matches))
.route("/match/:id", get(match_page)) .route("/match/:id", get(match_page))
.route("/maps/:format", get(map_history))
.with_state(AppState::default()); .with_state(AppState::default());
// run it // run it
@ -180,3 +181,21 @@ async fn match_page(
let response = state.client.match_info(id).await?; let response = state.client.match_info(id).await?;
Ok(Json(response)) Ok(Json(response))
} }
#[instrument(skip(state))]
async fn map_history(
Path(format): Path<String>,
State(state): State<AppState>,
) -> Result<impl IntoResponse, ApiError> {
let mode = match GameMode::from_str(&format) {
Ok(mode) => mode,
_ => {
return Err(ApiError::Mallformared(format!(
"invalid game mode {}",
format
)))
}
};
let response = state.client.map_history(mode).await?;
Ok(Json(response))
}

View file

@ -177,7 +177,7 @@ impl UgcClient {
pub async fn map_history(&self, format: GameMode) -> Result<MapHistory> { pub async fn map_history(&self, format: GameMode) -> Result<MapHistory> {
let link = format!( let link = format!(
"https://www.ugcleague.com/rostertransactions_tf2{}_all.cfm", "https://www.ugcleague.com/maplist_tf2{}.cfm",
format.letter() format.letter()
); );
let body = self.client.get(link).send().await?.text().await?; let body = self.client.get(link).send().await?.text().await?;

View file

@ -128,7 +128,6 @@ impl Parser for MapHistoryParser {
.first_text() .first_text()
.unwrap_or_default() .unwrap_or_default()
.trim_start_matches("Season "); .trim_start_matches("Season ");
dbg!(season);
let season = season.parse().map_err(|_| ParseError::InvalidText { let season = season.parse().map_err(|_| ParseError::InvalidText {
role: "previous season number", role: "previous season number",
text: season.to_string(), text: season.to_string(),