Remove Gist
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package de.jeyp91.apifootball;
|
||||
|
||||
import de.jeyp91.gists.GistProvider;
|
||||
import de.jeyp91.ResourceProvider;
|
||||
import de.jeyp91.S3Provider;
|
||||
import org.apache.http.HttpResponse;
|
||||
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 java.io.*;
|
||||
@@ -12,51 +14,42 @@ import java.util.HashSet;
|
||||
|
||||
public class APIFootballUpdater {
|
||||
|
||||
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\"}}";
|
||||
|
||||
public APIFootballUpdater(int season) {
|
||||
this.season = season;
|
||||
this.provider = GistProvider.getInstance();
|
||||
public APIFootballUpdater() {
|
||||
|
||||
}
|
||||
|
||||
public void updateFixtures(int league) throws IOException {
|
||||
public void updateFixtures(int league) {
|
||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
|
||||
String filename = "matches_league_" + league + ".json";
|
||||
String content = getRawData(apiFootballUrl);
|
||||
if(!content.equals(this.exceededLimitError)) {
|
||||
writeStringToGist(filename, content);
|
||||
S3Provider prov = new S3Provider();
|
||||
prov.writeFixturesToS3(league, content);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAllFixtures() throws IOException {
|
||||
HashSet<Integer> leagues = provider.getLeagues();
|
||||
public void updateAllFixtures() {
|
||||
HashSet<Integer> leagues = getLeagues();
|
||||
for (Integer league : leagues) {
|
||||
updateFixtures(league);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateRounds(int league) throws IOException {
|
||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
|
||||
String filename = "rounds_" + league + ".json";
|
||||
String content = getRawData(apiFootballUrl);
|
||||
if(!content.equals(this.exceededLimitError)) {
|
||||
writeStringToGist(filename, content);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAllRounds() throws IOException {
|
||||
HashSet<Integer> leagues = provider.getLeagues();
|
||||
public void updateAllRounds() {
|
||||
HashSet<Integer> leagues = getLeagues();
|
||||
for (Integer league : leagues) {
|
||||
updateRounds(league);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeStringToGist(String filename, String content) throws UnsupportedEncodingException {
|
||||
String id = this.provider.getGistID("APIFootball_" + this.season);
|
||||
this.provider.updateGist(id, filename, content);
|
||||
public void updateRounds(int league) {
|
||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
|
||||
String content = getRawData(apiFootballUrl);
|
||||
if(!content.equals(this.exceededLimitError)) {
|
||||
S3Provider prov = new S3Provider();
|
||||
prov.writeRoundsToS3(league, content);
|
||||
}
|
||||
}
|
||||
|
||||
public String getRawData(String requestUrl) {
|
||||
@@ -103,4 +96,15 @@ public class APIFootballUpdater {
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public HashSet<Integer> getLeagues() {
|
||||
JSONArray leaguesArray = ResourceProvider.getLigenConfig();
|
||||
HashSet<Integer> leagues = new HashSet<>();
|
||||
for (Object leagueObject : leaguesArray) {
|
||||
JSONObject leagueJSONObject = (JSONObject) leagueObject;
|
||||
Integer leagueId = ((Long) leagueJSONObject.get("league_id")).intValue();
|
||||
leagues.add(leagueId);
|
||||
}
|
||||
return leagues;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user