Skip to content

Commit

Permalink
Updated sofascore check
Browse files Browse the repository at this point in the history
  • Loading branch information
This-Is-Ko committed Oct 12, 2024
1 parent 430941e commit 87aba98
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 87aba98

Please sign in to comment.