Refactor API Football to v3

This commit is contained in:
2025-01-26 22:03:10 +01:00
parent 31d33aa0f8
commit f5735721e2
24 changed files with 1719 additions and 242 deletions
@@ -1,14 +1,15 @@
package de.jeyp91.apifootball;
import de.jeyp91.S3Provider;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.util.ArrayList;
import java.util.HashMap;
import de.jeyp91.S3Provider;
public class APIFootballConnector {
@@ -33,7 +34,7 @@ public class APIFootballConnector {
APIFootballMatch matchWithID = null;
ArrayList<APIFootballMatch> allMatches = getMatchesFromLeagueFromFile(league);
ArrayList<APIFootballMatch> allMatches = getMatchesFromLeagueFromFile(this.season, league);
for (APIFootballMatch singleMatch : allMatches) {
if (singleMatch.getAPIFootBallMatchID() == id) {
matchWithID = singleMatch;
@@ -48,7 +49,7 @@ public class APIFootballConnector {
ArrayList<APIFootballMatch> matchesOfMatchday = new ArrayList<>();
ArrayList<APIFootballMatch> allMatches = getMatchesFromLeagueFromFile(league);
ArrayList<APIFootballMatch> allMatches = getMatchesFromLeagueFromFile(this.season, league);
for (APIFootballMatch singleMatch : allMatches) {
if (singleMatch.getMatchday() == matchday) {
matchesOfMatchday.add(singleMatch);
@@ -58,15 +59,15 @@ public class APIFootballConnector {
return matchesOfMatchday;
}
public ArrayList<APIFootballMatch> getMatchesFromLeagueFromFile(int leagueId) {
public ArrayList<APIFootballMatch> getMatchesFromLeagueFromFile(int season, int leagueId) {
ArrayList<APIFootballMatch> matchesList = new ArrayList<>();
S3Provider prov = new S3Provider();
if(!this.matches.containsKey(leagueId)) {
this.matches.put(leagueId, prov.getFixturesJSONFromS3(leagueId));
this.matches.put(leagueId, prov.getFixturesJSONFromS3(season, leagueId));
}
JSONObject matches = this.matches.get(leagueId);
JSONArray matchArray = (JSONArray) (((JSONObject)matches.get("api")).get("fixtures"));
JSONObject matchesObject = this.matches.get(leagueId);
JSONArray matchArray = (JSONArray) (matchesObject.get("response"));
for(int i = 0; i < matchArray.size(); i++) {
try {
@@ -83,19 +84,18 @@ public class APIFootballConnector {
public JSONObject getMatchdays(int leagueId) {
S3Provider prov = new S3Provider();
if(!this.rounds.containsKey(leagueId)) {
this.rounds.put(leagueId, prov.getRoundsJSONFromS3(leagueId));
this.rounds.put(leagueId, prov.getRoundsJSONFromS3(this.season, leagueId));
}
return this.rounds.get(leagueId);
}
public JSONObject getTeamsForLeague(int league) throws Exception {
String url = "https://v2.api-football.com/teams/league/" + league;
String content = new APIFootballUpdater().getRawData(url);
public JSONObject getTeamsForLeague(int season, int league) throws Exception {
String requestPath = "teams";
String content = new APIFootballUpdater().getRawData(requestPath, season, league);
return stringToJSONObject(content);
}
public static JSONObject stringToJSONObject(String rawData) {
JSONParser parser = new JSONParser();
JSONObject data = null;
try {