Small fixes and workarounds

This commit is contained in:
2025-01-28 19:56:18 +01:00
parent 38fba7b906
commit 32bc791bd0
5 changed files with 38 additions and 16 deletions

4
.vscode/launch.json vendored
View File

@@ -10,7 +10,7 @@
"request": "launch", "request": "launch",
"mainClass": "de.jeyp91.App", "mainClass": "de.jeyp91.App",
"envFile": "${workspaceFolder}/.env", "envFile": "${workspaceFolder}/.env",
"args": " --mode APIFootballUpdater --season 2025 --league 1 --configFile Tippliga" "args": " --mode APIFootballUpdater --season 2024 --league 1 --configFile Tippliga"
}, },
{ {
"type": "java", "type": "java",
@@ -18,7 +18,7 @@
"request": "launch", "request": "launch",
"mainClass": "de.jeyp91.App", "mainClass": "de.jeyp91.App",
"envFile": "${workspaceFolder}/.env", "envFile": "${workspaceFolder}/.env",
"args": " --mode MatchesUpdaterFootball --season 2025 --league 1 --configFile Tippliga" "args": " --mode MatchesUpdaterFootball --season 2024 --league 49 --configFile Tippliga"
}, },
{ {
"type": "java", "type": "java",

View File

@@ -36,7 +36,7 @@ pipeline {
build wait: false, job: 'TippligaUpdater' build wait: false, job: 'TippligaUpdater'
build wait: false, job: 'WTLPokalUpdater' build wait: false, job: 'WTLPokalUpdater'
build wait: false, job: 'SupercupUpdater' build wait: false, job: 'SupercupUpdater'
build wait: false, job: 'LigaCupUpdater' // build wait: false, job: 'LigaCupUpdater'
} }
} }
} }

View File

@@ -8,6 +8,8 @@ import java.nio.charset.StandardCharsets;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider; import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
import software.amazon.awssdk.core.exception.SdkClientException; import software.amazon.awssdk.core.exception.SdkClientException;
@@ -15,6 +17,7 @@ import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectRequest; import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.NoSuchKeyException;
import software.amazon.awssdk.services.s3.model.PutObjectRequest; import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.S3Exception; import software.amazon.awssdk.services.s3.model.S3Exception;
@@ -23,6 +26,8 @@ public class S3Provider {
private static final String BUCKET_NAME = "tlw-database-tool-api-football-data"; private static final String BUCKET_NAME = "tlw-database-tool-api-football-data";
private final S3Client s3; private final S3Client s3;
private static final Logger logger = LoggerFactory.getLogger(S3Provider.class);
public S3Provider() { public S3Provider() {
s3 = S3Client.builder() s3 = S3Client.builder()
.region(AWS_DEFAULT_REGION) .region(AWS_DEFAULT_REGION)
@@ -45,12 +50,20 @@ public class S3Provider {
} }
public void writeFixturesToS3(int season, int league, String content) { 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) { 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) { private String getFileFromS3(String filename) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@@ -67,6 +80,8 @@ public class S3Provider {
} }
} catch (SdkClientException | IOException e) { } catch (SdkClientException | IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchKeyException e) {
logger.error(filename + " not found in S3.");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
@@ -83,6 +98,9 @@ public class S3Provider {
} }
private JSONObject stringToJSONObject(String rawData) { private JSONObject stringToJSONObject(String rawData) {
if(rawData.isEmpty()) {
return null;
}
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
JSONObject data = null; JSONObject data = null;
try { try {

View File

@@ -8,11 +8,11 @@ import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.jeyp91.ResourceProvider; import de.jeyp91.ResourceProvider;
import de.jeyp91.S3Provider; import de.jeyp91.S3Provider;
@@ -20,7 +20,7 @@ import de.jeyp91.S3Provider;
public class APIFootballUpdater { public class APIFootballUpdater {
private static final Logger logger = LoggerFactory.getLogger(APIFootballUpdater.class); private static final Logger logger = LoggerFactory.getLogger(APIFootballUpdater.class);
private static final String baseurl = "https://v3.football.api-sports.io/"; private static final String BASE_URL = "https://v3.football.api-sports.io/";
public APIFootballUpdater() { public APIFootballUpdater() {
@@ -99,7 +99,7 @@ public class APIFootballUpdater {
public String getRawData(String requestPath, int season, int league) throws Exception { public String getRawData(String requestPath, int season, int league) throws Exception {
HttpClient client = HttpClientBuilder.create().build(); HttpClient client = HttpClientBuilder.create().build();
String requestUrl = baseurl + requestPath + "?season=" + (season-1) + "&league=" + league + "&timezone=Europe/Berlin"; String requestUrl = BASE_URL + requestPath + "?season=" + (season-1) + "&league=" + league + "&timezone=Europe/Berlin";
HttpGet request = new HttpGet(requestUrl); HttpGet request = new HttpGet(requestUrl);
// add request header // add request header
@@ -136,8 +136,7 @@ public class APIFootballUpdater {
String errorMessage = resultObject.get("errors").toString(); String errorMessage = resultObject.get("errors").toString();
throw new Exception(requestUrl + " returned error: '" + errorMessage + "'"); throw new Exception(requestUrl + " returned error: '" + errorMessage + "'");
} else if (results == 0) { } else if (results == 0) {
String statusMessage = ((JSONObject) resultObject.get("api")).get("status").toString(); throw new Exception(requestUrl + " did not have any results.");
throw new Exception(requestUrl + " did not have any results with status: '" + statusMessage + "'");
} }
} }

View File

@@ -14,18 +14,23 @@ import de.jeyp91.apifootball.APIFootballMatch;
public class MatchesListCreator { public class MatchesListCreator {
private final JSONObject mainObject = new JSONObject(); private final JSONObject mainObject = new JSONObject();
private final String country; private String country;
private final String leagueName; private String leagueName;
private int season; private final int season;
private int league;
public MatchesListCreator(int season, int league) { public MatchesListCreator(int season, int league) {
this.season = season; this.season = season;
this.league = league;
S3Provider prov = new S3Provider(); S3Provider prov = new S3Provider();
JSONObject leagueConfig = prov.getFixturesJSONFromS3(season, league); JSONObject leagueConfig = prov.getFixturesJSONFromS3(season, league);
if (leagueConfig == null) {
return;
}
JSONArray matchesAPIFootball = (JSONArray) leagueConfig.get("response"); JSONArray matchesAPIFootball = (JSONArray) leagueConfig.get("response");
if(matchesAPIFootball.isEmpty()) {
return;
}
JSONObject firstMatchAPIFootball = (JSONObject) matchesAPIFootball.get(0); JSONObject firstMatchAPIFootball = (JSONObject) matchesAPIFootball.get(0);
JSONObject leagueObject = (JSONObject) firstMatchAPIFootball.get("league"); JSONObject leagueObject = (JSONObject) firstMatchAPIFootball.get("league");
this.country = leagueObject.get("country").toString(); this.country = leagueObject.get("country").toString();