Add check for limit excetion for api football and fix bug in switch in app
This commit is contained in:
@@ -45,9 +45,11 @@ public class App {
|
|||||||
case "TeamsUpdater":
|
case "TeamsUpdater":
|
||||||
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile);
|
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile);
|
||||||
sql = teamsUpdater.getInsertSQL();
|
sql = teamsUpdater.getInsertSQL();
|
||||||
|
break;
|
||||||
case "APIFootballUpdater":
|
case "APIFootballUpdater":
|
||||||
APIFootballUpdater apiFootballUpdater = new APIFootballUpdater(season);
|
APIFootballUpdater apiFootballUpdater = new APIFootballUpdater(season);
|
||||||
apiFootballUpdater.updateAllFixtures(configFile);
|
apiFootballUpdater.updateAllFixtures(configFile);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public class APIFootballUpdater {
|
|||||||
private int season;
|
private int season;
|
||||||
private GistProvider provider;
|
private GistProvider provider;
|
||||||
|
|
||||||
|
private final String exceededLimitError = "{\"api\":{\"results\":0,\"error\":\"You have reached the request limit for the day\"}}";
|
||||||
|
|
||||||
public APIFootballUpdater(int season) {
|
public APIFootballUpdater(int season) {
|
||||||
this.season = season;
|
this.season = season;
|
||||||
this.provider = GistProvider.getInstance();
|
this.provider = GistProvider.getInstance();
|
||||||
@@ -29,8 +31,10 @@ public class APIFootballUpdater {
|
|||||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
|
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
|
||||||
String filename = "matches_league_" + league + ".json";
|
String filename = "matches_league_" + league + ".json";
|
||||||
String content = getRawData(apiFootballUrl);
|
String content = getRawData(apiFootballUrl);
|
||||||
|
if(!content.equals(this.exceededLimitError)) {
|
||||||
writeStringToGist(filename, content);
|
writeStringToGist(filename, content);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void updateAllFixtures(String configPath) throws IOException {
|
public void updateAllFixtures(String configPath) throws IOException {
|
||||||
HashSet<Integer> leagues = getAllLeaguesFromLeagueConfig(configPath);
|
HashSet<Integer> leagues = getAllLeaguesFromLeagueConfig(configPath);
|
||||||
@@ -43,8 +47,10 @@ public class APIFootballUpdater {
|
|||||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
|
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
|
||||||
String filename = "rounds_" + league + ".json";
|
String filename = "rounds_" + league + ".json";
|
||||||
String content = getRawData(apiFootballUrl);
|
String content = getRawData(apiFootballUrl);
|
||||||
|
if(!content.equals(this.exceededLimitError)) {
|
||||||
writeStringToGist(filename, content);
|
writeStringToGist(filename, content);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void updateAllRounds(String configPath) throws IOException {
|
public void updateAllRounds(String configPath) throws IOException {
|
||||||
HashSet<Integer> leagues = getAllLeaguesFromLeagueConfig(configPath);
|
HashSet<Integer> leagues = getAllLeaguesFromLeagueConfig(configPath);
|
||||||
@@ -89,34 +95,6 @@ public class APIFootballUpdater {
|
|||||||
return leagues;
|
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) {
|
public String getRawData(String requestUrl) {
|
||||||
|
|
||||||
HttpClient client = HttpClientBuilder.create().build();
|
HttpClient client = HttpClientBuilder.create().build();
|
||||||
@@ -136,7 +114,6 @@ public class APIFootballUpdater {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BufferedReader rd = null;
|
BufferedReader rd = null;
|
||||||
try {
|
try {
|
||||||
rd = new BufferedReader(
|
rd = new BufferedReader(
|
||||||
|
|||||||
Reference in New Issue
Block a user