Finish gist

This commit is contained in:
2020-10-17 01:20:51 +02:00
parent e4186457e2
commit cb01b7bcb7
51 changed files with 155 additions and 132281 deletions

View File

@@ -13,8 +13,6 @@ import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
public class APIFootballUpdater {
@@ -24,7 +22,7 @@ public class APIFootballUpdater {
public APIFootballUpdater(int season) {
this.season = season;
this.provider = new GistProvider();
this.provider = GistProvider.getInstance();
}
public void updateFixtures(int league) throws IOException {
@@ -41,23 +39,36 @@ public class APIFootballUpdater {
}
}
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);
writeStringToGist(filename, content);
}
public void updateAllRounds(String configPath) throws IOException {
HashSet<Integer> leagues = getAllLeaguesFromLeagueConfig(configPath);
for (Integer league : leagues) {
updateRounds(league);
}
}
private void writeStringToGist(String filename, String content) throws UnsupportedEncodingException {
String id = this.provider.getGistID("Matches_" + this.season);
String id = this.provider.getGistID("APIFootball_" + this.season);
this.provider.updateGist(id, filename, content);
}
private HashSet<Integer> getAllLeaguesFromLeagueConfig(String configPath) {
private HashSet<Integer> getAllLeaguesFromLeagueConfig(String config) {
HashSet<Integer> leagues = new HashSet<>();
JSONParser jsonParser = new JSONParser();
URL url = Resources.getResource(season + "\\" + configPath);
String jsonConfig = null;
GistProvider prov = GistProvider.getInstance();
String jsonConfig = prov.getTippligaConfig(this.season, config);
JSONObject configObject = null;
try {
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
configObject = (JSONObject) jsonParser.parse(jsonConfig);
} catch (IOException | ParseException e) {
} catch (ParseException e) {
e.printStackTrace();
}