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

@@ -2,6 +2,7 @@ package de.jeyp91.apifootball;
import com.google.common.io.Resources;
import de.jeyp91.BaseMatch;
import de.jeyp91.gists.GistProvider;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -43,7 +44,8 @@ public class APIFootballMatch extends BaseMatch {
private int getMatchdayFromRoundString(String round, int leagueId) {
round = round.replace(" ", "_");
Integer matchday = null;
JSONObject roundsObject = readFromFile("rounds_" + leagueId + ".json");
APIFootballConnector con = APIFootballConnector.getAPIFootballConnectorInstance(this.season);
JSONObject roundsObject = con.getMatchdays(leagueId);
JSONArray roundsArray = (JSONArray)(((JSONObject) roundsObject.get("api")).get("fixtures"));
for (int i = 0; i < roundsArray.size(); i++) {
if(roundsArray.get(i).toString().equals(round)) {
@@ -54,26 +56,6 @@ public class APIFootballMatch extends BaseMatch {
return matchday;
}
private JSONObject readFromFile(String filename) {
JSONObject object = null;
//JSON parser object to parse read file
JSONParser jsonParser = new JSONParser();
URL url = Resources.getResource((this.season + 1) + "\\API-Football\\" + filename);
String jsonConfig = null;
try {
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
//Read JSON file
object = (JSONObject) jsonParser.parse(jsonConfig);
} catch (IOException | ParseException e) {
e.printStackTrace();
}
return object;
}
private Integer getNumberOrNull(Object object) {
return object != null ? Integer.parseInt(object.toString()) : null;
}