Add check for limit excetion for api football and fix bug in switch in app

This commit is contained in:
2020-10-25 21:50:46 +01:00
parent 306bf69107
commit 1e9ee8127c
2 changed files with 10 additions and 31 deletions

View File

@@ -45,9 +45,11 @@ public class App {
case "TeamsUpdater":
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile);
sql = teamsUpdater.getInsertSQL();
break;
case "APIFootballUpdater":
APIFootballUpdater apiFootballUpdater = new APIFootballUpdater(season);
apiFootballUpdater.updateAllFixtures(configFile);
break;
default:
break;
}

View File

@@ -20,6 +20,8 @@ public class APIFootballUpdater {
private int season;
private GistProvider provider;
private final String exceededLimitError = "{\"api\":{\"results\":0,\"error\":\"You have reached the request limit for the day\"}}";
public APIFootballUpdater(int season) {
this.season = season;
this.provider = GistProvider.getInstance();
@@ -29,7 +31,9 @@ public class APIFootballUpdater {
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
String filename = "matches_league_" + league + ".json";
String content = getRawData(apiFootballUrl);
writeStringToGist(filename, content);
if(!content.equals(this.exceededLimitError)) {
writeStringToGist(filename, content);
}
}
public void updateAllFixtures(String configPath) throws IOException {
@@ -43,7 +47,9 @@ public class APIFootballUpdater {
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
String filename = "rounds_" + league + ".json";
String content = getRawData(apiFootballUrl);
writeStringToGist(filename, content);
if(!content.equals(this.exceededLimitError)) {
writeStringToGist(filename, content);
}
}
public void updateAllRounds(String configPath) throws IOException {
@@ -89,34 +95,6 @@ public class APIFootballUpdater {
return leagues;
}
private JSONArray getDataAsJSONArray(String requestUrl) {
String rawData = getRawData(requestUrl);
JSONParser parser = new JSONParser();
JSONArray data = null;
try {
data = (JSONArray) parser.parse(rawData);
} catch (ParseException e) {
/* TODO */
e.printStackTrace();
}
return data;
}
public JSONObject getDataAsJSONObject(String requestUrl) {
String rawData = getRawData(requestUrl);
JSONParser parser = new JSONParser();
JSONObject data = null;
try {
data = (JSONObject) parser.parse(rawData);
} catch (ParseException e) {
/* TODO */
e.printStackTrace();
}
return data;
}
public String getRawData(String requestUrl) {
HttpClient client = HttpClientBuilder.create().build();
@@ -136,7 +114,6 @@ public class APIFootballUpdater {
e.printStackTrace();
}
BufferedReader rd = null;
try {
rd = new BufferedReader(