Finish gist

This commit is contained in:
2020-10-17 01:20:51 +02:00
parent 9e50c1a37e
commit 8c7b082867
51 changed files with 155 additions and 132281 deletions
@@ -1,14 +1,11 @@
package de.jeyp91.tippliga;
import com.google.common.io.Resources;
import de.jeyp91.gists.GistProvider;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -28,13 +25,13 @@ public class TLWMatchdaysCreator {
TLWMatchesCreatorFootball matchesCreator = new TLWMatchesCreatorFootball(2021, 1, configPath);
this.matches = matchesCreator.getMatches();
GistProvider prov = GistProvider.getInstance();
String jsonConfig = prov.getTippligaConfig(season, configPath);
JSONParser jsonParser = new JSONParser();
URL url = Resources.getResource(season + "\\" + configPath);
String jsonConfig = null;
try {
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
this.configObject = (JSONObject) jsonParser.parse(jsonConfig);
} catch (IOException | ParseException e) {
} catch (ParseException e) {
e.printStackTrace();
}
//Read JSON file
@@ -3,6 +3,7 @@ package de.jeyp91.tippliga;
import com.google.common.io.Resources;
import de.jeyp91.apifootball.APIFootballConnector;
import de.jeyp91.apifootball.APIFootballMatch;
import de.jeyp91.gists.GistProvider;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -31,21 +32,20 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
this.season = season;
this.league = league;
this.conn = new APIFootballConnector(season - 1);
this.conn = APIFootballConnector.getAPIFootballConnectorInstance(season - 1);
URL url = Resources.getResource(season + "\\" + configFileName);
String jsonConfig = null;
GistProvider prov = GistProvider.getInstance();
String jsonConfig = prov.getTippligaConfig(2021, configFileName);
try {
JSONParser jsonParser = new JSONParser();
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
//Read JSON file
JSONObject config = (JSONObject) jsonParser.parse(jsonConfig);
this.numberOfMatchdays = ((Long) config.get("numberOfMatchdays")).intValue();
this.matchdayConfig = (JSONArray) config.get("matchdayConfig");
this.ko = ((Long) config.get("ko")).intValue();
} catch (IOException | ParseException e) {
} catch (ParseException e) {
e.printStackTrace();
}
@@ -1,7 +1,7 @@
package de.jeyp91.tippliga;
import com.google.common.io.Resources;
import de.jeyp91.StatusHolder;
import de.jeyp91.gists.GistProvider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONArray;
@@ -9,9 +9,6 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
public class TLWMatchesCreatorTipperLeague extends TLWMatchesCreatorBase {
@@ -31,23 +28,20 @@ public class TLWMatchesCreatorTipperLeague extends TLWMatchesCreatorBase {
this.league = league;
this.matchdays = matchdays;
URL matchPairConfigUrl = Resources.getResource("Tipper_Match_Pair_Config.json");
URL tipperListUrl = Resources.getResource(season + "\\" + configFileName);
URL tipperTeamConfigUrl = Resources.getResource("Tipper_Team_Config.json");
try {
JSONParser jsonParser = new JSONParser();
GistProvider prov = GistProvider.getInstance();
String matchPairingConfigString = Resources.toString(matchPairConfigUrl, StandardCharsets.UTF_8);
String matchPairingConfigString = prov.getTippligaBaseConfig("Tipper_Match_Pair_Config.json");
this.matchPairingConfig = (JSONArray) jsonParser.parse(matchPairingConfigString);
String tipperListString = Resources.toString(tipperListUrl, StandardCharsets.UTF_8);
String tipperListString = prov.getTippligaConfig(season, configFileName);
this.tipperList = (JSONObject) jsonParser.parse(tipperListString);
String tipperTeamConfigString = Resources.toString(tipperTeamConfigUrl, StandardCharsets.UTF_8);
String tipperTeamConfigString = prov.getTippligaBaseConfig("Tipper_Team_Config.json");
this.tipperTeamConfig = (JSONArray) jsonParser.parse(tipperTeamConfigString);
} catch (IOException | ParseException e) {
} catch (ParseException e) {
e.printStackTrace();
}
@@ -1,6 +1,6 @@
package de.jeyp91.tippliga;
import com.google.common.io.Resources;
import de.jeyp91.gists.GistProvider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONArray;
@@ -8,9 +8,6 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
public class TLWMatchesCreatorTipperPokal extends TLWMatchesCreatorBase{
@@ -30,21 +27,21 @@ public class TLWMatchesCreatorTipperPokal extends TLWMatchesCreatorBase{
this.league = league;
this.matchdays = matchdays;
URL tipperListUrl = Resources.getResource(season + "\\" + configFileName);
URL tipperTeamConfigUrl = Resources.getResource("Tipper_Team_Config.json");
GistProvider prov = GistProvider.getInstance();
this.TLWMatches = new ArrayList<>();
try {
JSONParser jsonParser = new JSONParser();
String tipperListString = Resources.toString(tipperListUrl, StandardCharsets.UTF_8);
String tipperListString = prov.getTippligaConfig(season, configFileName);
this.tipperList = (JSONObject) jsonParser.parse(tipperListString);
String tipperTeamConfigString = Resources.toString(tipperTeamConfigUrl, StandardCharsets.UTF_8);
String tipperTeamConfigString = prov.getTippligaBaseConfig("Tipper_Team_Config.json");
this.tipperTeamConfig = (JSONArray) jsonParser.parse(tipperTeamConfigString);
} catch (IOException | ParseException e) {
} catch (ParseException e) {
e.printStackTrace();
}
@@ -1,15 +1,11 @@
package de.jeyp91.tippliga;
import com.google.common.io.Resources;
import de.jeyp91.gists.GistProvider;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -25,18 +21,17 @@ public class TLWMatchesManagerBase {
protected void initConfigParamsFromFile(String configFileName) {
URL url = Resources.getResource(season + File.separator + configFileName);
String jsonConfig = null;
GistProvider prov = GistProvider.getInstance();
String jsonConfig = prov.getTippligaConfig(season, configFileName);
try {
JSONParser jsonParser = new JSONParser();
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
//Read JSON file
JSONObject config = (JSONObject) jsonParser.parse(jsonConfig);
this.numberOfMatchdays = ((Long) config.get("numberOfMatchdays")).intValue();
this.matchdayConfig = (JSONArray) config.get("matchdayConfig");
this.ko = ((Long) config.get("ko")).intValue();
} catch (IOException | ParseException e) {
} catch (ParseException e) {
e.printStackTrace();
}
}
@@ -1,11 +1,14 @@
package de.jeyp91.tippliga;
import com.google.api.client.util.DateTime;
import de.jeyp91.TeamIDMatcher;
import de.jeyp91.apifootball.APIFootballMatch;
import de.jeyp91.apifootball.APIFootballMatchesProvider;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
@@ -133,7 +136,13 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
{
for(APIFootballMatch apiFootballMatch : apiFootballMatches) {
TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatches);
tlwMatch.setMatchDateTime(apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19));
OffsetDateTime offsetDateTime = OffsetDateTime.parse(apiFootballMatch.getMatchDateTime());
ZonedDateTime now = ZonedDateTime.now();
ZoneOffset offsetNow = now.getOffset();
OffsetDateTime fixedDatetime = offsetDateTime.withOffsetSameInstant(offsetNow);
String newMatchTime = fixedDatetime.toString();
tlwMatch.setMatchDateTime(newMatchTime.replace("T", " ").substring(0, 16) + ":00");
}
}