Improve handling for leagues without matches this season (ex. world cup)

This commit is contained in:
2025-04-19 18:33:49 +02:00
parent 9c060863f6
commit c35d28951e
2 changed files with 15 additions and 14 deletions

View File

@@ -50,19 +50,11 @@ public class S3Provider {
}
public void writeFixturesToS3(int season, int league, String content) {
if (league == 1 || league == 4) {
writeToS3(v3Filepath("fixtures", season-1, league), content);
} else {
writeToS3(v3Filepath("fixtures", season, league), content);
}
writeToS3(v3Filepath("fixtures", season, league), content);
}
public void writeRoundsToS3(int season, int league, String content) {
if (league == 1 || league == 4) {
writeToS3(v3Filepath("rounds", season-1, league), content);
} else {
writeToS3(v3Filepath("rounds", season, league), content);
}
writeToS3(v3Filepath("rounds", season, league), content);
}
private String getFileFromS3(String filename) {

View File

@@ -97,9 +97,17 @@ public class APIFootballUpdater {
}
public String getRawData(String requestPath, int season, int league) throws Exception {
if(league != 1 && league != 4) {
/**
* Season usually is one higher in Tippliga than in API-Football.
* e.g. 2023/24 is 2024 in Tippliga and 2023 in API-Football.
* Because Liga Cup in Tippliga is at the end of a season, season does match World Cup (1) and Euro Championship (4)
*/
season--;
}
HttpClient client = HttpClientBuilder.create().build();
String requestUrl = BASE_URL + requestPath + "?season=" + (season-1) + "&league=" + league + "&timezone=Europe/Berlin";
String requestUrl = BASE_URL + requestPath + "?season=" + (season) + "&league=" + league + "&timezone=Europe/Berlin";
HttpGet request = new HttpGet(requestUrl);
// add request header
@@ -131,13 +139,14 @@ public class APIFootballUpdater {
public void checkErrors(String requestUrl, String result) throws Exception {
JSONObject resultObject = stringToJSONObject(result);
boolean containsError = !((JSONArray) resultObject.get("errors")).isEmpty();
int results = Integer.parseInt(resultObject.get("results").toString());
// int results = Integer.parseInt(resultObject.get("results").toString());
if(containsError) {
String errorMessage = resultObject.get("errors").toString();
throw new Exception(requestUrl + " returned error: '" + errorMessage + "'");
} else if (results == 0) {
throw new Exception(requestUrl + " did not have any results.");
}
// else if (results == 0) {
// throw new Exception(requestUrl + " did not have any results.");
// }
}
private JSONObject stringToJSONObject(String rawData) {