From c35d28951e6b3e5b92b6cf18b85fff212085afe3 Mon Sep 17 00:00:00 2001 From: Julian Arndt Date: Sat, 19 Apr 2025 18:33:49 +0200 Subject: [PATCH] Improve handling for leagues without matches this season (ex. world cup) --- src/main/java/de/jeyp91/S3Provider.java | 12 ++---------- .../jeyp91/apifootball/APIFootballUpdater.java | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/jeyp91/S3Provider.java b/src/main/java/de/jeyp91/S3Provider.java index 3fdaa8b..b49a304 100644 --- a/src/main/java/de/jeyp91/S3Provider.java +++ b/src/main/java/de/jeyp91/S3Provider.java @@ -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) { diff --git a/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java b/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java index a902216..8aa9b92 100644 --- a/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java +++ b/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java @@ -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) {