Improve error output and add team id matcher template creator

This commit is contained in:
2020-11-04 21:22:27 +01:00
parent 2f411aae67
commit d42edcf01c
15 changed files with 158 additions and 154 deletions

View File

@@ -1,24 +1,19 @@
package de.jeyp91.apifootball;
import com.google.common.io.Resources;
import de.jeyp91.gists.GistProvider;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.*;
import java.util.HashSet;
public class APIFootballUpdater {
private int season;
private GistProvider provider;
private final int season;
private final GistProvider provider;
private final String exceededLimitError = "{\"api\":{\"results\":0,\"error\":\"You have reached the request limit for the day\"}}";
@@ -36,8 +31,8 @@ public class APIFootballUpdater {
}
}
public void updateAllFixtures(String configPath) throws IOException {
HashSet<Integer> leagues = getAllLeaguesFromLeagueConfig(configPath);
public void updateAllFixtures() throws IOException {
HashSet<Integer> leagues = provider.getLeagues();
for (Integer league : leagues) {
updateFixtures(league);
}
@@ -52,8 +47,8 @@ public class APIFootballUpdater {
}
}
public void updateAllRounds(String configPath) throws IOException {
HashSet<Integer> leagues = getAllLeaguesFromLeagueConfig(configPath);
public void updateAllRounds() throws IOException {
HashSet<Integer> leagues = provider.getLeagues();
for (Integer league : leagues) {
updateRounds(league);
}
@@ -64,37 +59,6 @@ public class APIFootballUpdater {
this.provider.updateGist(id, filename, content);
}
public static HashSet<Integer> getAllLeaguesFromLeagueConfig(String config) {
HashSet<Integer> leagues = new HashSet<>();
JSONParser jsonParser = new JSONParser();
GistProvider prov = GistProvider.getInstance();
String jsonConfig = prov.getTippligaConfig(config);
JSONObject configObject = null;
try {
configObject = (JSONObject) jsonParser.parse(jsonConfig);
} catch (ParseException e) {
e.printStackTrace();
}
JSONArray matchdayConfigs = (JSONArray) configObject.get("matchdayConfig");
for (Object matchdayConfig : matchdayConfigs) {
JSONArray matchesConfig = (JSONArray) ((JSONObject) matchdayConfig).get("matchesConfig");
for (Object matchConfig : matchesConfig) {
if (((JSONObject) matchConfig).containsKey("matchesLeague")) {
int league = Integer.parseInt(((JSONObject) matchConfig).get("matchesLeague").toString());
leagues.add(league);
}
if (((JSONObject) matchConfig).containsKey("matchLeague")) {
int league = Integer.parseInt(((JSONObject) matchConfig).get("matchLeague").toString());
leagues.add(league);
}
}
}
return leagues;
}
public String getRawData(String requestUrl) {
HttpClient client = HttpClientBuilder.create().build();
@@ -106,9 +70,6 @@ public class APIFootballUpdater {
HttpResponse response = null;
try {
response = client.execute(request);
} catch (ClientProtocolException e) {
/* TODO */
e.printStackTrace();
} catch (IOException e) {
/* TODO */
e.printStackTrace();
@@ -116,6 +77,7 @@ public class APIFootballUpdater {
BufferedReader rd = null;
try {
assert response != null;
rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent())
);