From 87aba98a74f5948506438883f1dbf5418773abe4 Mon Sep 17 00:00:00 2001 From: This-Is-Ko <52279273+This-Is-Ko@users.noreply.github.com> Date: Sat, 12 Oct 2024 18:45:01 +1100 Subject: [PATCH] Updated sofascore check --- .../datasource/SofascoreDataSource.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/ko/footballupdater/datasource/SofascoreDataSource.java b/src/main/java/com/ko/footballupdater/datasource/SofascoreDataSource.java index 542b4b2..77a1e0c 100644 --- a/src/main/java/com/ko/footballupdater/datasource/SofascoreDataSource.java +++ b/src/main/java/com/ko/footballupdater/datasource/SofascoreDataSource.java @@ -10,6 +10,7 @@ import com.ko.footballupdater.models.Team; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.jsoup.HttpStatusException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.springframework.beans.factory.annotation.Qualifier; @@ -80,6 +81,18 @@ public PlayerMatchPerformanceStats parsePlayerMatchData(Player player, Document } } + // Check that match is finished + if (matchEntry.hasNonNull("status") && matchEntry.get("status").hasNonNull("code")) { + int matchStatusCode = matchEntry.get("status").get("code").intValue(); + if (matchStatusCode != 100) { + log.atInfo().setMessage("Selected match status is not 100 - not finished").addKeyValue("player", player.getName()).log(); + return null; + } + } else { + log.atInfo().setMessage("Selected match is missing status node or status code").addKeyValue("player", player.getName()).log(); + return null; + } + // Construct player match statistics url // e.g. https://api.sofascore.com/api/v1/event/11859193/player/796007/statistics int matchId = matchEntry.get("id").intValue(); @@ -162,6 +175,8 @@ public PlayerMatchPerformanceStats parsePlayerMatchData(Player player, Document Match match = new Match(url, selectedMatchDate, homeTeam, awayTeam, relevantTeamName, homeTeamScore, awayTeamScore); playerMatchPerformanceStats.setMatch(match); return playerMatchPerformanceStats; + } catch (HttpStatusException ex) { + log.atWarn().setMessage("Error while trying to update player - HTTP code: " + ex.getStatusCode() + " - url: " + ex.getUrl()).addKeyValue("player", player.getName()).log(); } catch (Exception ex) { log.atWarn().setMessage("Error while trying to update player").setCause(ex).addKeyValue("player", player.getName()).log(); }