Add auto update of results
This commit is contained in:
11
jenkinsfiles/SupercupUpdater/Jenkinsfile
vendored
11
jenkinsfiles/SupercupUpdater/Jenkinsfile
vendored
@@ -11,12 +11,19 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
String jdkPath = tool name: 'OpenJDK', type: 'jdk'
|
String jdkPath = tool name: 'OpenJDK', type: 'jdk'
|
||||||
withCredentials([usernamePassword(credentialsId: 'aws', passwordVariable: 'AWS_SECRET_KEY', usernameVariable: 'AWS_ACCESS_KEY_ID')]) {
|
withCredentials([
|
||||||
withEnv(["JAVA_HOME=${jdkPath}/jdk-19.0.2","AWS_SECRET_KEY=${AWS_SECRET_KEY}", "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"]) {
|
usernamePassword(credentialsId: 'aws', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_KEY'),
|
||||||
|
usernamePassword(credentialsId: 'forum_database', usernameVariable: 'TLW_DATABASE_USERNAME', passwordVariable: 'TLW_DATABASE_PASSWORD'),
|
||||||
|
usernamePassword(credentialsId: 'forum_user', usernameVariable: 'FORUM_USERNAME', passwordVariable: 'FORUM_PASSWORD')
|
||||||
|
]) {
|
||||||
|
withEnv([
|
||||||
|
"JAVA_HOME=${jdkPath}/jdk-19.0.2"
|
||||||
|
]) {
|
||||||
try {
|
try {
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesUpdaterFootball --season ${season} --league 45 --configFile Supercup 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesUpdaterFootball --season ${season} --league 45 --configFile Supercup 2>&1 >> log.txt"
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchdaysUpdater --season ${season} --league 45 --configFile Supercup 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchdaysUpdater --season ${season} --league 45 --configFile Supercup 2>&1 >> log.txt"
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode TeamsUpdater --season ${season} --league 45 --configFile Supercup 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode TeamsUpdater --season ${season} --league 45 --configFile Supercup 2>&1 >> log.txt"
|
||||||
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesResultsUpdater --season ${season} --league 45 --configFile Supercup 2>&1 >> log.txt"
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
telegramSendManual("TLW-Database-Tool crashed!")
|
telegramSendManual("TLW-Database-Tool crashed!")
|
||||||
}
|
}
|
||||||
|
|||||||
12
jenkinsfiles/TippligaUpdater/Jenkinsfile
vendored
12
jenkinsfiles/TippligaUpdater/Jenkinsfile
vendored
@@ -11,16 +11,24 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
String jdkPath = tool name: 'OpenJDK19', type: 'jdk'
|
String jdkPath = tool name: 'OpenJDK19', type: 'jdk'
|
||||||
withCredentials([usernamePassword(credentialsId: 'aws', passwordVariable: 'AWS_SECRET_KEY', usernameVariable: 'AWS_ACCESS_KEY_ID')]) {
|
withCredentials([
|
||||||
withEnv(["JAVA_HOME=${jdkPath}/jdk-19.0.2", "AWS_SECRET_KEY=${AWS_SECRET_KEY}", "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"]) {
|
usernamePassword(credentialsId: 'aws', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_KEY'),
|
||||||
|
usernamePassword(credentialsId: 'forum_database', usernameVariable: 'TLW_DATABASE_USERNAME', passwordVariable: 'TLW_DATABASE_PASSWORD'),
|
||||||
|
usernamePassword(credentialsId: 'forum_user', usernameVariable: 'FORUM_USERNAME', passwordVariable: 'FORUM_PASSWORD')
|
||||||
|
]) {
|
||||||
|
withEnv([
|
||||||
|
"JAVA_HOME=${jdkPath}/jdk-19.0.2"
|
||||||
|
]) {
|
||||||
try {
|
try {
|
||||||
sh "ls build/libs"
|
sh "ls build/libs"
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesUpdaterFootball --season ${season} --league 1 --configFile Tippliga 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesUpdaterFootball --season ${season} --league 1 --configFile Tippliga 2>&1 >> log.txt"
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchdaysUpdater --season ${season} --league 1 --configFile Tippliga 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchdaysUpdater --season ${season} --league 1 --configFile Tippliga 2>&1 >> log.txt"
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode TeamsUpdater --season ${season} --league 1 --configFile Tippliga 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode TeamsUpdater --season ${season} --league 1 --configFile Tippliga 2>&1 >> log.txt"
|
||||||
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesResultsUpdater --season ${season} --league 1 --configFile Tippliga 2>&1 >> log.txt"
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesUpdaterFootball --season ${season} --league 2 --configFile Tippliga 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesUpdaterFootball --season ${season} --league 2 --configFile Tippliga 2>&1 >> log.txt"
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchdaysUpdater --season ${season} --league 2 --configFile Tippliga 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchdaysUpdater --season ${season} --league 2 --configFile Tippliga 2>&1 >> log.txt"
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode TeamsUpdater --season ${season} --league 2 --configFile Tippliga 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode TeamsUpdater --season ${season} --league 2 --configFile Tippliga 2>&1 >> log.txt"
|
||||||
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesResultsUpdater --season ${season} --league 2 --configFile Tippliga 2>&1 >> log.txt"
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
telegramSendManual("TLW-Database-Tool crashed!")
|
telegramSendManual("TLW-Database-Tool crashed!")
|
||||||
}
|
}
|
||||||
|
|||||||
11
jenkinsfiles/WTLPokalUpdater/Jenkinsfile
vendored
11
jenkinsfiles/WTLPokalUpdater/Jenkinsfile
vendored
@@ -11,12 +11,19 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
String jdkPath = tool name: 'OpenJDK19', type: 'jdk'
|
String jdkPath = tool name: 'OpenJDK19', type: 'jdk'
|
||||||
withCredentials([usernamePassword(credentialsId: 'aws', passwordVariable: 'AWS_SECRET_KEY', usernameVariable: 'AWS_ACCESS_KEY_ID')]) {
|
withCredentials([
|
||||||
withEnv(["JAVA_HOME=${jdkPath}/jdk-19.0.2","AWS_SECRET_KEY=${AWS_SECRET_KEY}", "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"]) {
|
usernamePassword(credentialsId: 'aws', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_KEY'),
|
||||||
|
usernamePassword(credentialsId: 'forum_database', usernameVariable: 'TLW_DATABASE_USERNAME', passwordVariable: 'TLW_DATABASE_PASSWORD'),
|
||||||
|
usernamePassword(credentialsId: 'forum_user', usernameVariable: 'FORUM_USERNAME', passwordVariable: 'FORUM_PASSWORD')
|
||||||
|
]) {
|
||||||
|
withEnv([
|
||||||
|
"JAVA_HOME=${jdkPath}/jdk-19.0.2"
|
||||||
|
]) {
|
||||||
try {
|
try {
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesUpdaterFootball --season ${season} --league 48 --configFile WTL-Pokal 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesUpdaterFootball --season ${season} --league 48 --configFile WTL-Pokal 2>&1 >> log.txt"
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchdaysUpdater --season ${season} --league 48 --configFile WTL-Pokal 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchdaysUpdater --season ${season} --league 48 --configFile WTL-Pokal 2>&1 >> log.txt"
|
||||||
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode TeamsUpdater --season ${season} --league 48 --configFile WTL-Pokal 2>&1 >> log.txt"
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode TeamsUpdater --season ${season} --league 48 --configFile WTL-Pokal 2>&1 >> log.txt"
|
||||||
|
sh "java -jar build/libs/tlw-database-tool-1.0.jar --mode MatchesResultsUpdater --season ${season} --league 48 --configFile WTL-Pokal 2>&1 >> log.txt"
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
telegramSendManual("TLW-Database-Tool crashed!")
|
telegramSendManual("TLW-Database-Tool crashed!")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ public class App {
|
|||||||
sql = tlwMatchesUpdaterFootball.getUpdateSQL();
|
sql = tlwMatchesUpdaterFootball.getUpdateSQL();
|
||||||
beautifulInfo = tlwMatchesUpdaterFootball.getBeautifulInfo();
|
beautifulInfo = tlwMatchesUpdaterFootball.getBeautifulInfo();
|
||||||
break;
|
break;
|
||||||
|
case "MatchesResultsUpdater":
|
||||||
|
TLWMatchesResultsUpdater tlwMatchesResultsUpdater = new TLWMatchesResultsUpdater(season, league, configFile);
|
||||||
|
beautifulInfo = tlwMatchesResultsUpdater.getBeautifulInfo();
|
||||||
|
break;
|
||||||
case "TeamsUpdater":
|
case "TeamsUpdater":
|
||||||
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile);
|
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile);
|
||||||
sql = teamsUpdater.getInsertSQL();
|
sql = teamsUpdater.getInsertSQL();
|
||||||
@@ -94,7 +98,7 @@ public class App {
|
|||||||
|
|
||||||
parser.addArgument("-m", "--mode")
|
parser.addArgument("-m", "--mode")
|
||||||
.dest("mode")
|
.dest("mode")
|
||||||
.choices("MatchdaysUpdater", "MatchesCreatorFootball", "MatchesUpdaterFootball", "TeamsUpdater", "APIFootballUpdater", "MatchesListGistUpdater", "PostChecksum")
|
.choices("MatchdaysUpdater", "MatchesCreatorFootball", "MatchesUpdaterFootball", "MatchesResultsUpdater", "TeamsUpdater", "APIFootballUpdater", "MatchesListGistUpdater", "PostChecksum")
|
||||||
.help("")
|
.help("")
|
||||||
.required(true)
|
.required(true)
|
||||||
.type(String.class);
|
.type(String.class);
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package de.jeyp91;
|
|||||||
|
|
||||||
public abstract class BaseMatch {
|
public abstract class BaseMatch {
|
||||||
|
|
||||||
public final Integer COMPARISON_IDENTICAL = 0;
|
public static final Integer COMPARISON_IDENTICAL = 0;
|
||||||
public final Integer COMPARISON_DIFFERENT = 1;
|
public static final Integer COMPARISON_DIFFERENT = 1;
|
||||||
public final Integer COMPARISON_DIFFERENT_DATETIME = 2;
|
public static final Integer COMPARISON_DIFFERENT_DATETIME = 2;
|
||||||
public final Integer COMPARISON_DIFFERENT_RESULT = 3;
|
public static final Integer COMPARISON_DIFFERENT_RESULT = 3;
|
||||||
|
|
||||||
protected Integer teamIdHome;
|
protected Integer teamIdHome;
|
||||||
protected Integer teamIdGuest;
|
protected Integer teamIdGuest;
|
||||||
@@ -18,6 +18,8 @@ public abstract class BaseMatch {
|
|||||||
protected Integer matchday = null;
|
protected Integer matchday = null;
|
||||||
protected String matchDatetime = null;
|
protected String matchDatetime = null;
|
||||||
|
|
||||||
|
protected Integer updateStatus = COMPARISON_IDENTICAL;
|
||||||
|
|
||||||
public Integer getMatchday() {
|
public Integer getMatchday() {
|
||||||
return this.matchday;
|
return this.matchday;
|
||||||
}
|
}
|
||||||
@@ -57,4 +59,10 @@ public abstract class BaseMatch {
|
|||||||
public String getTeamNameGuest() {
|
public String getTeamNameGuest() {
|
||||||
return this.teamNameGuest;
|
return this.teamNameGuest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUpdateStatus(Integer newStatus) { this.updateStatus = newStatus; }
|
||||||
|
|
||||||
|
public Integer getUpdateStatus() {
|
||||||
|
return this.updateStatus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ import org.apache.logging.log4j.Logger;
|
|||||||
*/
|
*/
|
||||||
public class TLWMatch extends BaseMatch{
|
public class TLWMatch extends BaseMatch{
|
||||||
|
|
||||||
public final Integer STATUS_NOTSTARTED = 0;
|
public static final Integer STATUS_NOTSTARTED = 0;
|
||||||
public final Integer STATUS_STARTED = 1;
|
public static final Integer STATUS_STARTED = 1;
|
||||||
public final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
|
public static final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
|
||||||
public final Integer STATUS_FINISHED = 3;
|
public static final Integer STATUS_FINISHED = 3;
|
||||||
|
public static final Integer STATUS_NOT_EVALUATED = 4;
|
||||||
|
|
||||||
private Integer season = null;
|
private Integer season = null;
|
||||||
private Integer league = null;
|
private Integer league = null;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package de.jeyp91.tippliga;
|
package de.jeyp91.tippliga;
|
||||||
|
|
||||||
import de.jeyp91.apifootball.APIFootballMatch;
|
import de.jeyp91.apifootball.APIFootballMatch;
|
||||||
|
import de.jeyp91.teamidmatcher.TeamIDMatcher;
|
||||||
import de.jeyp91.tippligaforum.TippligaConfigProvider;
|
import de.jeyp91.tippligaforum.TippligaConfigProvider;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
@@ -100,4 +101,28 @@ public class TLWMatchesManagerBase {
|
|||||||
date2 = date2.toLocalDate().atTime(0, 0, 0);
|
date2 = date2.toLocalDate().atTime(0, 0, 0);
|
||||||
return (int) date1.until(date2, ChronoUnit.DAYS);
|
return (int) date1.until(date2, ChronoUnit.DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected TLWMatch getMatchingMatch(APIFootballMatch apiFootballMatch, ArrayList<TLWMatch> tlwMatches) throws NullPointerException{
|
||||||
|
int foundMatches = 0;
|
||||||
|
TLWMatch matchingMatch = null;
|
||||||
|
for(TLWMatch match : tlwMatches) {
|
||||||
|
Integer apiTeamIdHome = TeamIDMatcher.getTippligaIdFromApiFootballId(apiFootballMatch, TeamIDMatcher.HOME);
|
||||||
|
Integer apiTeamIdGuest = TeamIDMatcher.getTippligaIdFromApiFootballId(apiFootballMatch, TeamIDMatcher.GUEST);
|
||||||
|
int tlwTeamIdHome = match.getTeamIdHome();
|
||||||
|
int tlwTeamIdGuest = match.getTeamIdGuest();
|
||||||
|
|
||||||
|
if(apiTeamIdHome == null
|
||||||
|
|| apiTeamIdGuest == null) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
if(
|
||||||
|
apiTeamIdHome.equals(tlwTeamIdHome)
|
||||||
|
&& apiTeamIdGuest.equals(tlwTeamIdGuest)
|
||||||
|
) {
|
||||||
|
foundMatches++;
|
||||||
|
matchingMatch = match;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matchingMatch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
140
src/main/java/de/jeyp91/tippliga/TLWMatchesResultsUpdater.java
Normal file
140
src/main/java/de/jeyp91/tippliga/TLWMatchesResultsUpdater.java
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
package de.jeyp91.tippliga;
|
||||||
|
|
||||||
|
import de.jeyp91.StatusHolder;
|
||||||
|
import de.jeyp91.apifootball.APIFootballMatch;
|
||||||
|
import de.jeyp91.apifootball.APIFootballMatchesProvider;
|
||||||
|
import de.jeyp91.teamidmatcher.TeamIDMatcher;
|
||||||
|
import de.jeyp91.tippligaforum.TippligaSQLConnector;
|
||||||
|
import de.jeyp91.tippligaforum.TippligaWebsiteConnector;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
|
||||||
|
private static final Logger logger = LogManager.getLogger(TLWMatchesResultsUpdater.class);
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<ArrayList<TLWMatch>> tlwMatchesUpdated = new ArrayList<>();
|
||||||
|
|
||||||
|
private String beautifulInfo = "";
|
||||||
|
|
||||||
|
public TLWMatchesResultsUpdater(int season, int league, String configFileName) {
|
||||||
|
this.season = season;
|
||||||
|
this.league = league;
|
||||||
|
|
||||||
|
super.initConfigParamsFromFile(configFileName);
|
||||||
|
initUpdates();
|
||||||
|
applyUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initUpdates() {
|
||||||
|
|
||||||
|
APIFootballMatchesProvider apiFootballMatchesProvider = new APIFootballMatchesProvider(this.season);
|
||||||
|
TippligaSQLConnector tippligaSQLConnector = TippligaSQLConnector.getInstance();
|
||||||
|
for (Object singleMatchdayConfig : this.matchdayConfig) {
|
||||||
|
int tlwMatchday = ((Long) ((JSONObject) singleMatchdayConfig).get("TLWMatchday")).intValue();
|
||||||
|
JSONArray matchesConfig = (JSONArray) ((JSONObject) singleMatchdayConfig).get("matchesConfig");
|
||||||
|
|
||||||
|
ArrayList<APIFootballMatch> apiFootballMatches = apiFootballMatchesProvider.getAPIFootballMatchesFromConfig(matchesConfig);
|
||||||
|
|
||||||
|
ArrayList<TLWMatch> tlwMatchesOriginalMatchday = tippligaSQLConnector.getMatches(String.valueOf(this.season), String.valueOf(this.league), String.valueOf(tlwMatchday));
|
||||||
|
ArrayList<TLWMatch> tlwMatchesUpdatedMatchday = new ArrayList<>();
|
||||||
|
for (TLWMatch match : tlwMatchesOriginalMatchday) {
|
||||||
|
tlwMatchesUpdatedMatchday.add(new TLWMatch(match));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiFootballMatches.size() > tlwMatchesOriginalMatchday.size()) {
|
||||||
|
logger.error("Not matching config!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(apiFootballMatches.size() > 0) {
|
||||||
|
updateResults(tlwMatchesUpdatedMatchday, apiFootballMatches);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateBeautifulInfo(tlwMatchesOriginalMatchday, tlwMatchesUpdatedMatchday);
|
||||||
|
tlwMatchesUpdatedMatchday.removeIf(tlwMatch -> tlwMatch.getUpdateStatus() != TLWMatch.COMPARISON_DIFFERENT_RESULT);
|
||||||
|
if(tlwMatchesUpdatedMatchday.size() > 0) this.tlwMatchesUpdated.add(tlwMatchesUpdatedMatchday);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyUpdates() {
|
||||||
|
TippligaWebsiteConnector con;
|
||||||
|
try {
|
||||||
|
con = new TippligaWebsiteConnector();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
this.tlwMatchesUpdated.forEach(tlwMatches -> {
|
||||||
|
con.updateResultsAdmin(this.season, this.league, tlwMatches.get(0).getMatchday(), tlwMatches);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateResults(
|
||||||
|
ArrayList<TLWMatch> tlwMatchesUpdated,
|
||||||
|
ArrayList<APIFootballMatch> apiFootballMatches)
|
||||||
|
{
|
||||||
|
ArrayList<TLWMatch> tlwMatchesCopy = new ArrayList<>(tlwMatchesUpdated);
|
||||||
|
for(APIFootballMatch apiFootballMatch : apiFootballMatches) {
|
||||||
|
try {
|
||||||
|
TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatchesCopy);
|
||||||
|
tlwMatchesCopy.remove(tlwMatch);
|
||||||
|
if(Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_STARTED)
|
||||||
|
|| Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_PROVISIONAL_RESULT_AVAILABLE)
|
||||||
|
|| Objects.equals(tlwMatch.getStatus(), TLWMatch.STATUS_FINISHED)) {
|
||||||
|
if(!Objects.equals(tlwMatch.getGoalsHome(), apiFootballMatch.getGoalsHome())
|
||||||
|
|| !Objects.equals(tlwMatch.getGoalsGuest(), apiFootballMatch.getGoalsGuest())
|
||||||
|
) {
|
||||||
|
tlwMatch.setGoalsHome(apiFootballMatch.getGoalsHome());
|
||||||
|
tlwMatch.setGoalsGuest(apiFootballMatch.getGoalsGuest());
|
||||||
|
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
|
||||||
|
}
|
||||||
|
if(tlwMatch.getKoMatch() == 1 &&
|
||||||
|
(!Objects.equals(tlwMatch.getGoalsOvertimeHome(), apiFootballMatch.getGoalsOvertimeHome())
|
||||||
|
|| !Objects.equals(tlwMatch.getGoalsOvertimeGuest(), apiFootballMatch.getGoalsOvertimeGuest()))
|
||||||
|
) {
|
||||||
|
tlwMatch.setGoalsOvertimeHome(apiFootballMatch.getGoalsOvertimeHome());
|
||||||
|
tlwMatch.setGoalsOvertimeGuest(apiFootballMatch.getGoalsOvertimeGuest());
|
||||||
|
tlwMatch.setUpdateStatus(TLWMatch.COMPARISON_DIFFERENT_RESULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NullPointerException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBeautifulInfo(ArrayList<TLWMatch> matchesOriginal, ArrayList<TLWMatch> matchesUpdated) {
|
||||||
|
for (int i = 0; i < matchesOriginal.size(); i++) {
|
||||||
|
updateBeautifulInfo(matchesOriginal.get(i), matchesUpdated.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBeautifulInfo(TLWMatch matchOriginal, TLWMatch matchUpdated) {
|
||||||
|
String beautifulInfoStart = "Aktualisiere Saison " + matchOriginal.getSeason() + ", " +
|
||||||
|
"Liga " + matchOriginal.getLeague() + ", " +
|
||||||
|
"Spieltag " + matchOriginal.getMatchday() + ", " +
|
||||||
|
"Spielnummer " + matchOriginal.getMatchNo() + ", " +
|
||||||
|
"Spiel '" + TeamIDMatcher.getTeamNameFromTippligaId(matchOriginal.getTeamIdHome()) + "' - '" + TeamIDMatcher.getTeamNameFromTippligaId(matchOriginal.getTeamIdGuest()) + "', ";
|
||||||
|
|
||||||
|
if(!Objects.equals(matchOriginal.getGoalsHome(), matchUpdated.getGoalsHome()) || !Objects.equals(matchOriginal.getGoalsGuest(), matchUpdated.getGoalsGuest())) {
|
||||||
|
this.beautifulInfo += beautifulInfoStart +
|
||||||
|
"Ergebnis zu '" + matchUpdated.getGoalsHome() + ":" + matchUpdated.getGoalsGuest() + "'.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(matchOriginal.getKoMatch() == 1 && (!Objects.equals(matchOriginal.getGoalsOvertimeHome(), matchUpdated.getGoalsOvertimeHome()) || !Objects.equals(matchOriginal.getGoalsOvertimeGuest(), matchUpdated.getGoalsOvertimeGuest()))) {
|
||||||
|
this.beautifulInfo += beautifulInfoStart +
|
||||||
|
"Ergebnis Nachspielzeit zu '" + matchUpdated.getGoalsOvertimeHome() + ":" + matchUpdated.getGoalsOvertimeGuest() + "'.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBeautifulInfo() {
|
||||||
|
return this.beautifulInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -220,30 +220,6 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TLWMatch getMatchingMatch(APIFootballMatch apiFootballMatch, ArrayList<TLWMatch> tlwMatches) throws NullPointerException{
|
|
||||||
int foundMatches = 0;
|
|
||||||
TLWMatch matchingMatch = null;
|
|
||||||
for(TLWMatch match : tlwMatches) {
|
|
||||||
Integer apiTeamIdHome = TeamIDMatcher.getTippligaIdFromApiFootballId(apiFootballMatch, TeamIDMatcher.HOME);
|
|
||||||
Integer apiTeamIdGuest = TeamIDMatcher.getTippligaIdFromApiFootballId(apiFootballMatch, TeamIDMatcher.GUEST);
|
|
||||||
int tlwTeamIdHome = match.getTeamIdHome();
|
|
||||||
int tlwTeamIdGuest = match.getTeamIdGuest();
|
|
||||||
|
|
||||||
if(apiTeamIdHome == null
|
|
||||||
|| apiTeamIdGuest == null) {
|
|
||||||
throw new NullPointerException();
|
|
||||||
}
|
|
||||||
if(
|
|
||||||
apiTeamIdHome.equals(tlwTeamIdHome)
|
|
||||||
&& apiTeamIdGuest.equals(tlwTeamIdGuest)
|
|
||||||
) {
|
|
||||||
foundMatches++;
|
|
||||||
matchingMatch = match;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return matchingMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<TLWMatch> getTLWMatchesUpdated() {
|
public ArrayList<TLWMatch> getTLWMatchesUpdated() {
|
||||||
return this.tlwMatchesUpdated;
|
return this.tlwMatchesUpdated;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public class TippligaSQLConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private TippligaSQLConnector() {
|
private TippligaSQLConnector() {
|
||||||
|
String databaseUsername = System.getenv("TLW_DATABASE_USERNAME");
|
||||||
|
String databasePassword = System.getenv("TLW_DATABASE_PASSWORD");
|
||||||
String jdbcUrlLocalhost = "jdbc:mysql://localhost:3306/d0144ddb" +
|
String jdbcUrlLocalhost = "jdbc:mysql://localhost:3306/d0144ddb" +
|
||||||
"?user=root" +
|
"?user=root" +
|
||||||
"&password=" +
|
"&password=" +
|
||||||
@@ -44,8 +46,8 @@ public class TippligaSQLConnector {
|
|||||||
"&serverTimezone=UTC" +
|
"&serverTimezone=UTC" +
|
||||||
"&allowMultiQueries=true";
|
"&allowMultiQueries=true";
|
||||||
String jdbcUrlProd = "jdbc:mysql://w00f4eaf.kasserver.com:3306/d0144ddb" +
|
String jdbcUrlProd = "jdbc:mysql://w00f4eaf.kasserver.com:3306/d0144ddb" +
|
||||||
"?user=d0144ddb" +
|
"?user=" + databaseUsername +
|
||||||
"&password=TippligaWuerzb_1" +
|
"&password=" + databasePassword +
|
||||||
"&useUnicode=true" +
|
"&useUnicode=true" +
|
||||||
"&useJDBCCompliantTimezoneShift=true" +
|
"&useJDBCCompliantTimezoneShift=true" +
|
||||||
"&useLegacyDatetimeCode=false" +
|
"&useLegacyDatetimeCode=false" +
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package de.jeyp91.tippligaforum;
|
package de.jeyp91.tippligaforum;
|
||||||
|
|
||||||
|
import de.jeyp91.tippliga.TLWMatch;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@@ -24,9 +25,10 @@ public class TippligaWebsiteConnector {
|
|||||||
CookieStore cookieStore = cm.getCookieStore();
|
CookieStore cookieStore = cm.getCookieStore();
|
||||||
private static final Logger logger = LogManager.getLogger(TippligaWebsiteConnector.class);
|
private static final Logger logger = LogManager.getLogger(TippligaWebsiteConnector.class);
|
||||||
private final HttpClient client;
|
private final HttpClient client;
|
||||||
|
private final String username = System.getenv("FORUM_USERNAME");
|
||||||
private final String username = "Julian";
|
private final String password = System.getenv("FORUM_PASSWORD");
|
||||||
private final String password = "original";
|
private String lastCreationTime = "";
|
||||||
|
private String lastFormToken = "";
|
||||||
|
|
||||||
public TippligaWebsiteConnector() throws IOException {
|
public TippligaWebsiteConnector() throws IOException {
|
||||||
CookieHandler.setDefault(cm);
|
CookieHandler.setDefault(cm);
|
||||||
@@ -37,7 +39,6 @@ public class TippligaWebsiteConnector {
|
|||||||
.build();
|
.build();
|
||||||
login();
|
login();
|
||||||
adminLogin();
|
adminLogin();
|
||||||
updateResultsAdmin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void login() throws IOException {
|
private void login() throws IOException {
|
||||||
@@ -57,8 +58,8 @@ public class TippligaWebsiteConnector {
|
|||||||
Matcher matcher = pattern.matcher(reqBody);
|
Matcher matcher = pattern.matcher(reqBody);
|
||||||
matcher.find();
|
matcher.find();
|
||||||
|
|
||||||
String creationTime = matcher.group(1);
|
this.lastCreationTime = matcher.group(1);
|
||||||
String formToken = matcher.group(2);
|
this.lastFormToken = matcher.group(2);
|
||||||
String sid = matcher.group(3);
|
String sid = matcher.group(3);
|
||||||
|
|
||||||
Map<String, String> loginParameters = new HashMap<>();
|
Map<String, String> loginParameters = new HashMap<>();
|
||||||
@@ -68,8 +69,8 @@ public class TippligaWebsiteConnector {
|
|||||||
loginParameters.put("viewonline", "on");
|
loginParameters.put("viewonline", "on");
|
||||||
loginParameters.put("username", username);
|
loginParameters.put("username", username);
|
||||||
loginParameters.put("password", password);
|
loginParameters.put("password", password);
|
||||||
loginParameters.put("creation_time", creationTime);
|
loginParameters.put("creation_time", this.lastCreationTime);
|
||||||
loginParameters.put("form_token", formToken);
|
loginParameters.put("form_token", this.lastFormToken);
|
||||||
loginParameters.put("sid", sid);
|
loginParameters.put("sid", sid);
|
||||||
|
|
||||||
String loginForm = loginParameters.entrySet()
|
String loginForm = loginParameters.entrySet()
|
||||||
@@ -113,8 +114,8 @@ public class TippligaWebsiteConnector {
|
|||||||
Matcher matcher = pattern.matcher(reqBody);
|
Matcher matcher = pattern.matcher(reqBody);
|
||||||
matcher.find();
|
matcher.find();
|
||||||
|
|
||||||
String creationTime = matcher.group(1);
|
this.lastCreationTime = matcher.group(1);
|
||||||
String formToken = matcher.group(2);
|
this.lastFormToken = matcher.group(2);
|
||||||
sid = matcher.group(3);
|
sid = matcher.group(3);
|
||||||
String credential = matcher.group(4);
|
String credential = matcher.group(4);
|
||||||
|
|
||||||
@@ -123,8 +124,8 @@ public class TippligaWebsiteConnector {
|
|||||||
loginParameters.put("redirect", "./../adm/index.php?sid=" + sid);
|
loginParameters.put("redirect", "./../adm/index.php?sid=" + sid);
|
||||||
loginParameters.put("username", username);
|
loginParameters.put("username", username);
|
||||||
loginParameters.put("password_" + credential, password);
|
loginParameters.put("password_" + credential, password);
|
||||||
loginParameters.put("creation_time", creationTime);
|
loginParameters.put("creation_time", this.lastCreationTime);
|
||||||
loginParameters.put("form_token", formToken);
|
loginParameters.put("form_token", this.lastFormToken);
|
||||||
loginParameters.put("sid", sid);
|
loginParameters.put("sid", sid);
|
||||||
loginParameters.put("credential", credential);
|
loginParameters.put("credential", credential);
|
||||||
|
|
||||||
@@ -150,7 +151,7 @@ public class TippligaWebsiteConnector {
|
|||||||
List<HttpCookie> loginReqCookieList = cookieStore.getCookies();
|
List<HttpCookie> loginReqCookieList = cookieStore.getCookies();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateResultsAdmin() {
|
public void updateResultsAdmin(int season, int league, int matchday, List<TLWMatch> matches) {
|
||||||
String sid = getSidFromCookie();
|
String sid = getSidFromCookie();
|
||||||
String url = "https://tippliga-wuerzburg.de/adm/index.php?i=-football-football-acp-results_module&mode=manage&sid=" + sid;
|
String url = "https://tippliga-wuerzburg.de/adm/index.php?i=-football-football-acp-results_module&mode=manage&sid=" + sid;
|
||||||
|
|
||||||
@@ -170,26 +171,23 @@ public class TippligaWebsiteConnector {
|
|||||||
Matcher matcher = pattern.matcher(reqBody);
|
Matcher matcher = pattern.matcher(reqBody);
|
||||||
matcher.find();
|
matcher.find();
|
||||||
|
|
||||||
String creationTime = matcher.group(1);
|
this.lastCreationTime = matcher.group(1);
|
||||||
String formToken = matcher.group(2);
|
this.lastFormToken = matcher.group(2);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateResults() {
|
|
||||||
Map<String, String> resultParameters = new HashMap<>();
|
Map<String, String> resultParameters = new HashMap<>();
|
||||||
|
|
||||||
resultParameters.put("s", "2023");
|
resultParameters.put("s", String.valueOf(season));
|
||||||
resultParameters.put("l", "2");
|
resultParameters.put("l", String.valueOf(league));
|
||||||
resultParameters.put("m", "32");
|
resultParameters.put("m", String.valueOf(matchday));
|
||||||
resultParameters.put("action", "result");
|
resultParameters.put("edit", "Speichern");
|
||||||
resultParameters.put("goalsh384", "4");
|
resultParameters.put("creation_time", this.lastCreationTime);
|
||||||
resultParameters.put("oldgoalsh384", "4");
|
resultParameters.put("form_token", this.lastFormToken);
|
||||||
resultParameters.put("goalsg384", "3");
|
matches.forEach(tlwMatch -> {
|
||||||
resultParameters.put("oldgoalsg384", "4");
|
String matchNo = String.valueOf(tlwMatch.getMatchNo());
|
||||||
resultParameters.put("goalsh380", "");
|
resultParameters.put("select_" + matchNo, "on");
|
||||||
resultParameters.put("oldgoalsh380", "");
|
resultParameters.put("goals_home_" + matchNo, String.valueOf(tlwMatch.getGoalsHome()));
|
||||||
resultParameters.put("goalsg380", "");
|
resultParameters.put("goals_guest_" + matchNo, String.valueOf(tlwMatch.getGoalsGuest()));
|
||||||
resultParameters.put("oldgoalsg380", "");
|
});
|
||||||
|
|
||||||
String resultForm = resultParameters.entrySet()
|
String resultForm = resultParameters.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
@@ -197,7 +195,7 @@ public class TippligaWebsiteConnector {
|
|||||||
.collect(Collectors.joining("&"));
|
.collect(Collectors.joining("&"));
|
||||||
|
|
||||||
HttpRequest resultReq = HttpRequest.newBuilder()
|
HttpRequest resultReq = HttpRequest.newBuilder()
|
||||||
.uri(URI.create("https://tippliga-wuerzburg.de/app.php/football/results?s=2023&l=2&m=32&action=result"))
|
.uri(URI.create("https://tippliga-wuerzburg.de/adm/index.php?i=-football-football-acp-results_module&mode=manage&sid=" + sid))
|
||||||
.headers("Content-Type", "application/x-www-form-urlencoded")
|
.headers("Content-Type", "application/x-www-form-urlencoded")
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(resultForm))
|
.POST(HttpRequest.BodyPublishers.ofString(resultForm))
|
||||||
.build();
|
.build();
|
||||||
@@ -209,8 +207,11 @@ public class TippligaWebsiteConnector {
|
|||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
matcher = pattern.matcher(resultReqBody);
|
||||||
|
matcher.find();
|
||||||
|
|
||||||
logger.info(resultReqBody);
|
this.lastCreationTime = matcher.group(1);
|
||||||
|
this.lastFormToken = matcher.group(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSidFromCookie() {
|
private String getSidFromCookie() {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package de.jeyp91.tippliga;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TLWMatchesResultsUpdaterTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateResultsTest1() {
|
||||||
|
TLWMatchesResultsUpdater updater = new TLWMatchesResultsUpdater(2023, 2, "Tippliga");
|
||||||
|
System.out.println(updater.getBeautifulInfo());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,21 @@
|
|||||||
package de.jeyp91.tippligaforum;
|
package de.jeyp91.tippligaforum;
|
||||||
|
|
||||||
|
import de.jeyp91.tippliga.TLWMatch;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class TippligaWebsiteConnectorTest {
|
public class TippligaWebsiteConnectorTest {
|
||||||
@Test
|
@Test
|
||||||
public void getChecksumOfPostTest() throws IOException {
|
public void updateResultsAdminTest() throws IOException {
|
||||||
TippligaWebsiteConnector con = new TippligaWebsiteConnector();
|
TippligaWebsiteConnector con = new TippligaWebsiteConnector();
|
||||||
|
List<TLWMatch> matches = new ArrayList<>();
|
||||||
|
TLWMatch match = new TLWMatch(2023, 48, 5, 61, "0", 3, 0);
|
||||||
|
match.setGoalsHome(1);
|
||||||
|
match.setGoalsGuest(5);
|
||||||
|
matches.add(match);
|
||||||
|
con.updateResultsAdmin(2023, 48, 5, matches);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user