Improve match list in forum to match tlw league config

This commit is contained in:
Julian Arndt
2020-11-10 11:26:39 +01:00
parent f1ce35dcdf
commit 10e6348dcf
4 changed files with 17 additions and 7 deletions

View File

@@ -3,12 +3,13 @@ package de.jeyp91.tippligaforum;
import com.google.gson.*;
import de.jeyp91.S3Provider;
import de.jeyp91.apifootball.APIFootballMatch;
import netscape.javascript.JSObject;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class MatchesListCreator {
private final JSONObject matches = new JSONObject();
private final JSONObject mainObject = new JSONObject();
private final String country;
private final String leagueName;
@@ -17,12 +18,21 @@ public class MatchesListCreator {
JSONObject leagueConfig = prov.getFixturesJSONFromS3(league);
JSONObject api = (JSONObject) leagueConfig.get("api");
JSONArray matchesAPIFootball = (JSONArray) api.get("fixtures");
JSONObject firstMatchAPIFootball = (JSONObject) matchesAPIFootball.get(0);
JSONObject leagueObject = (JSONObject) firstMatchAPIFootball.get("league");
this.country = leagueObject.get("country").toString();
this.leagueName = leagueObject.get("name").toString();
JSONArray matches = populateMatches(matchesAPIFootball);
this.matches.put("matches", matches);
JSONArray matchesConfig = populateMatches(matchesAPIFootball);
JSONObject matchdayConfigObject = new JSONObject();
matchdayConfigObject.put("matchesConfig", matchesConfig);
JSONArray matchdayConfig = new JSONArray();
matchdayConfig.add(matchdayConfigObject);
this.mainObject.put("matchdayConfig", matchdayConfig);
}
private JSONArray populateMatches(JSONArray matchesAPIFootball) {
@@ -55,11 +65,11 @@ public class MatchesListCreator {
}
public JSONObject getMatches() {
return this.matches;
return this.mainObject;
}
public String getMatchesBeautiful() {
JsonElement jelement = JsonParser.parseString(this.matches.toString());
JsonElement jelement = JsonParser.parseString(this.mainObject.toString());
Gson gson = new GsonBuilder().setPrettyPrinting().create();
return gson.toJson(jelement);
}

View File

@@ -16,7 +16,7 @@ public class MatchesListCreatorTest {
public void getMatchesTest2743() {
MatchesListCreator creator = new MatchesListCreator(2743);
String matches = creator.getMatchesBeautiful();
// System.out.println(matches);
System.out.println(matches);
}
@Test

View File

@@ -16,6 +16,6 @@ public class MatchesListForumUpdaterTest {
@Test
public void updateLeagueTest() {
MatchesListForumUpdater updater = new MatchesListForumUpdater();
// updater.updateLeague(2743);
updater.updateLeague(2743);
}
}

Binary file not shown.