Compare commits

..

2 Commits

Author SHA1 Message Date
9cf286db39 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	src/main/java/de/jeyp91/tippliga/TLWMatchesResultsUpdater.java
#	src/test/java/de/jeyp91/tippliga/TLWMatchesResultsUpdaterTest.java
2023-06-06 15:49:54 +02:00
4dcd994ac9 Add auto update of results 2023-06-06 15:48:06 +02:00
13 changed files with 195 additions and 284 deletions

View File

@@ -11,12 +11,19 @@ pipeline {
steps {
script {
String jdkPath = tool name: 'OpenJDK', type: 'jdk'
withCredentials([usernamePassword(credentialsId: 'aws', passwordVariable: 'AWS_SECRET_KEY', usernameVariable: 'AWS_ACCESS_KEY_ID')]) {
withEnv(["JAVA_HOME=${jdkPath}/jdk-19.0.2","AWS_SECRET_KEY=${AWS_SECRET_KEY}", "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"]) {
withCredentials([
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 {
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 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) {
telegramSendManual("TLW-Database-Tool crashed!")
}

View File

@@ -11,16 +11,24 @@ pipeline {
steps {
script {
String jdkPath = tool name: 'OpenJDK19', type: 'jdk'
withCredentials([usernamePassword(credentialsId: 'aws', passwordVariable: 'AWS_SECRET_KEY', usernameVariable: 'AWS_ACCESS_KEY_ID')]) {
withEnv(["JAVA_HOME=${jdkPath}/jdk-19.0.2", "AWS_SECRET_KEY=${AWS_SECRET_KEY}", "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"]) {
withCredentials([
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 {
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 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 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 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 MatchesResultsUpdater --season ${season} --league 2 --configFile Tippliga 2>&1 >> log.txt"
} catch (Exception e) {
telegramSendManual("TLW-Database-Tool crashed!")
}

View File

@@ -11,12 +11,19 @@ pipeline {
steps {
script {
String jdkPath = tool name: 'OpenJDK19', type: 'jdk'
withCredentials([usernamePassword(credentialsId: 'aws', passwordVariable: 'AWS_SECRET_KEY', usernameVariable: 'AWS_ACCESS_KEY_ID')]) {
withEnv(["JAVA_HOME=${jdkPath}/jdk-19.0.2","AWS_SECRET_KEY=${AWS_SECRET_KEY}", "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"]) {
withCredentials([
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 {
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 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) {
telegramSendManual("TLW-Database-Tool crashed!")
}

View File

@@ -59,6 +59,10 @@ public class App {
sql = tlwMatchesUpdaterFootball.getUpdateSQL();
beautifulInfo = tlwMatchesUpdaterFootball.getBeautifulInfo();
break;
case "MatchesResultsUpdater":
TLWMatchesResultsUpdater tlwMatchesResultsUpdater = new TLWMatchesResultsUpdater(season, league, configFile);
beautifulInfo = tlwMatchesResultsUpdater.getBeautifulInfo();
break;
case "TeamsUpdater":
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile);
sql = teamsUpdater.getInsertSQL();
@@ -94,7 +98,7 @@ public class App {
parser.addArgument("-m", "--mode")
.dest("mode")
.choices("MatchdaysUpdater", "MatchesCreatorFootball", "MatchesUpdaterFootball", "TeamsUpdater", "APIFootballUpdater", "MatchesListGistUpdater", "PostChecksum")
.choices("MatchdaysUpdater", "MatchesCreatorFootball", "MatchesUpdaterFootball", "MatchesResultsUpdater", "TeamsUpdater", "APIFootballUpdater", "MatchesListGistUpdater", "PostChecksum")
.help("")
.required(true)
.type(String.class);

View File

@@ -2,10 +2,10 @@ package de.jeyp91;
public abstract class BaseMatch {
public final Integer COMPARISON_IDENTICAL = 0;
public final Integer COMPARISON_DIFFERENT = 1;
public final Integer COMPARISON_DIFFERENT_DATETIME = 2;
public final Integer COMPARISON_DIFFERENT_RESULT = 3;
public static final Integer COMPARISON_IDENTICAL = 0;
public static final Integer COMPARISON_DIFFERENT = 1;
public static final Integer COMPARISON_DIFFERENT_DATETIME = 2;
public static final Integer COMPARISON_DIFFERENT_RESULT = 3;
protected Integer teamIdHome;
protected Integer teamIdGuest;
@@ -18,6 +18,8 @@ public abstract class BaseMatch {
protected Integer matchday = null;
protected String matchDatetime = null;
protected Integer updateStatus = COMPARISON_IDENTICAL;
public Integer getMatchday() {
return this.matchday;
}
@@ -57,4 +59,10 @@ public abstract class BaseMatch {
public String getTeamNameGuest() {
return this.teamNameGuest;
}
public void setUpdateStatus(Integer newStatus) { this.updateStatus = newStatus; }
public Integer getUpdateStatus() {
return this.updateStatus;
}
}

View File

@@ -14,10 +14,11 @@ import org.apache.logging.log4j.Logger;
*/
public class TLWMatch extends BaseMatch{
public final Integer STATUS_NOTSTARTED = 0;
public final Integer STATUS_STARTED = 1;
public final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
public final Integer STATUS_FINISHED = 3;
public static final Integer STATUS_NOTSTARTED = 0;
public static final Integer STATUS_STARTED = 1;
public static final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
public static final Integer STATUS_FINISHED = 3;
public static final Integer STATUS_NOT_EVALUATED = 4;
private Integer season = null;
private Integer league = null;

View File

@@ -1,6 +1,7 @@
package de.jeyp91.tippliga;
import de.jeyp91.apifootball.APIFootballMatch;
import de.jeyp91.teamidmatcher.TeamIDMatcher;
import de.jeyp91.tippligaforum.TippligaConfigProvider;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
@@ -100,4 +101,28 @@ public class TLWMatchesManagerBase {
date2 = date2.toLocalDate().atTime(0, 0, 0);
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;
}
}

View File

@@ -1,35 +1,34 @@
package de.jeyp91.tippliga;
import de.jeyp91.StatusHolder;
import de.jeyp91.teamidmatcher.TeamIDMatcher;
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.time.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
private static final Logger logger = LogManager.getLogger(TLWMatchesUpdaterFootball.class);
public class TLWMatchesResultsUpdater extends TLWMatchesManagerBase {
private static final Logger logger = LogManager.getLogger(TLWMatchesResultsUpdater.class);
ArrayList<TLWMatch> tlwMatchesOriginal;
ArrayList<TLWMatch> tlwMatchesUpdated;
ArrayList<ArrayList<TLWMatch>> tlwMatchesUpdated = new ArrayList<>();
String beautifulInfo = "";
public TLWMatchesUpdaterFootball(int season, int league, String configFileName) {
public TLWMatchesResultsUpdater(int season, int league, String configFileName) {
this.season = season;
this.league = league;
tlwMatchesOriginal = new ArrayList<>();
tlwMatchesUpdated = new ArrayList<>();
super.initConfigParamsFromFile(configFileName);
this.initUpdates();
initUpdates();
applyUpdates();
}
private void initUpdates() {
@@ -48,204 +47,88 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
tlwMatchesUpdatedMatchday.add(new TLWMatch(match));
}
if (apiFootballMatches.size() > tlwMatchesUpdatedMatchday.size()) {
if (apiFootballMatches.size() > tlwMatchesOriginalMatchday.size()) {
logger.error("Not matching config!");
}
LocalDateTime now = LocalDateTime.now();
LocalDateTime firstMatchOriginal = TLWMatchesManagerBase.getFirstMatchtimeTLW(tlwMatchesOriginalMatchday);
LocalDateTime firstMatchUpdated = TLWMatchesManagerBase.getFirstMatchtimeAPIFootball(apiFootballMatches);
if(apiFootballMatches.size() > 0
&& now.isBefore(firstMatchOriginal)
&& now.isBefore(firstMatchUpdated)) {
addMissingMatches(tlwMatchesUpdatedMatchday, apiFootballMatches);
updateMatchDateTimes(tlwMatchesUpdatedMatchday, apiFootballMatches);
updateShowTable(tlwMatchesUpdatedMatchday, apiFootballMatches);
updateStatus(tlwMatchesUpdatedMatchday);
if(apiFootballMatches.size() > 0) {
updateResults(tlwMatchesUpdatedMatchday, apiFootballMatches);
}
this.tlwMatchesOriginal.addAll(tlwMatchesOriginalMatchday);
this.tlwMatchesUpdated.addAll(tlwMatchesUpdatedMatchday);
updateBeautifulInfo(tlwMatchesOriginalMatchday, tlwMatchesUpdatedMatchday);
tlwMatchesUpdatedMatchday.removeIf(tlwMatch -> tlwMatch.getUpdateStatus() != TLWMatch.COMPARISON_DIFFERENT_RESULT);
if(tlwMatchesUpdatedMatchday.size() > 0) this.tlwMatchesUpdated.add(tlwMatchesUpdatedMatchday);
}
}
public String getUpdateSQL() {
return this.getUpdateString(tlwMatchesOriginal, tlwMatchesUpdated);
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 String getUpdateString(ArrayList<TLWMatch> matchesOriginal, ArrayList<TLWMatch> matchesUpdated) {
String updateString = "";
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++) {
updateString += getUpdateString(matchesOriginal.get(i), matchesUpdated.get(i));
updateBeautifulInfo(matchesOriginal.get(i), matchesUpdated.get(i));
}
return updateString;
}
private String getUpdateString(TLWMatch matchOriginal, TLWMatch matchUpdated) {
String updateString = "";
String updateStart = "UPDATE phpbb_footb_matches SET ";
String condition = "WHERE season = " + matchOriginal.getSeason() + " " +
"AND league = " + matchOriginal.getLeague() + " " +
"AND matchday = " + matchOriginal.getMatchday() + " " +
"AND match_no = " + matchOriginal.getMatchNo() + ";\n";
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(!matchOriginal.getTeamIdHome().equals(matchUpdated.getTeamIdHome())) {
updateString += updateStart +
"team_id_home = " + matchUpdated.getTeamIdHome() + " " +
condition;
if(!Objects.equals(matchOriginal.getGoalsHome(), matchUpdated.getGoalsHome()) || !Objects.equals(matchOriginal.getGoalsGuest(), matchUpdated.getGoalsGuest())) {
this.beautifulInfo += beautifulInfoStart +
"Heimteam zu '" + matchUpdated.getTeamNameHome() + "'.\n";
"Ergebnis zu '" + matchUpdated.getGoalsHome() + ":" + matchUpdated.getGoalsGuest() + "'.\n";
}
if(!matchOriginal.getTeamIdGuest().equals(matchUpdated.getTeamIdGuest())) {
updateString += updateStart +
"team_id_guest = " + matchUpdated.getTeamIdGuest() + " " +
condition;
if(matchOriginal.getKoMatch() == 1 && (!Objects.equals(matchOriginal.getGoalsOvertimeHome(), matchUpdated.getGoalsOvertimeHome()) || !Objects.equals(matchOriginal.getGoalsOvertimeGuest(), matchUpdated.getGoalsOvertimeGuest()))) {
this.beautifulInfo += beautifulInfoStart +
"Gastteam zu '" + matchUpdated.getTeamNameGuest() + "'.\n";
"Ergebnis Nachspielzeit zu '" + matchUpdated.getGoalsOvertimeHome() + ":" + matchUpdated.getGoalsOvertimeGuest() + "'.\n";
}
if (!matchOriginal.getMatchDateTime().equals(matchUpdated.getMatchDateTime())) {
updateString += updateStart +
"match_datetime = '" + matchUpdated.getMatchDateTime() + "' " +
condition;
this.beautifulInfo += beautifulInfoStart +
"Spielbeginn zu '" + matchUpdated.getMatchDateTime() + "'.\n";
}
if (!matchOriginal.getStatus().equals(matchUpdated.getStatus())) {
updateString += updateStart +
"status = '" + matchUpdated.getStatus() + "' " +
condition;
this.beautifulInfo += beautifulInfoStart +
"Status zu '" + matchUpdated.getStatus() + "'.\n";
}
if (!matchOriginal.getShowTable().equals(matchUpdated.getShowTable())) {
updateString += updateStart +
"show_table = '" + matchUpdated.getShowTable() + "' " +
condition;
this.beautifulInfo += beautifulInfoStart +
"Spiel in Tabelle einberechnen zu '" + (matchUpdated.getShowTable() == 1 ? "falsch" : "wahr") + "'.\n";
}
return updateString;
}
private void addMissingMatches(ArrayList<TLWMatch> tlwMatches,
ArrayList<APIFootballMatch> apiFootballMatches) {
ArrayList<APIFootballMatch> missingMatches = new ArrayList<>();
for(APIFootballMatch apiFootballMatch : apiFootballMatches) {
try {
if(getMatchingMatch(apiFootballMatch, tlwMatches) == null) {
missingMatches.add(apiFootballMatch);
}
} catch (NullPointerException ignored) {
}
}
for (APIFootballMatch missingMatch : missingMatches) {
boolean done = false;
for(TLWMatch tlwMatch : tlwMatches) {
if(tlwMatch.getTeamIdHome() == 0 && tlwMatch.getTeamIdGuest() == 0) {
tlwMatch.updateMatch(missingMatch);
done = true;
break;
}
}
if(!done) {
logger.error("Could not add missing match: " + this.season + ", " + this.league + ", " + tlwMatches.get(0).getMatchday() + ", " + missingMatch.getTeamNameHome() + " - " + missingMatch.getTeamNameGuest());
}
}
}
private void updateMatchDateTimes(
ArrayList<TLWMatch> tlwMatches,
ArrayList<APIFootballMatch> apiFootballMatches)
{
ArrayList<TLWMatch> tlwMatchesCopy = new ArrayList<>(tlwMatches);
for(APIFootballMatch apiFootballMatch : apiFootballMatches) {
try {
TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatchesCopy);
tlwMatchesCopy.remove(tlwMatch);
if(tlwMatch == null) {
StatusHolder.setError();
logger.error("Did not find match to update: " + this.season + ", " + this.league + ", " + tlwMatches.get(0).getMatchday() + ", " + apiFootballMatch.getTeamNameHome() + " - " + apiFootballMatch.getTeamNameGuest());
}
tlwMatch.setMatchDateTime(apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19));
} catch(NullPointerException ignored) {
}
}
}
private void updateStatus(ArrayList<TLWMatch> matches) {
LocalDateTime earliestDate = TLWMatchesManagerBase.getFirstMatchtimeTLW(matches);
LocalDateTime now = LocalDateTime.now();
if(earliestDate.isAfter(now)) {
for(TLWMatch match : matches) {
LocalDateTime date = TLWMatchesManagerBase.getDate(match);
if (getDaysDifference(earliestDate, date) == 0) {
match.setStatus(0);
} else {
match.setStatus(-1);
}
}
}
}
private void updateShowTable(
ArrayList<TLWMatch> tlwMatches,
ArrayList<APIFootballMatch> apiFootballMatches)
{
ArrayList<TLWMatch> tlwMatchesCopy = new ArrayList<>(tlwMatches);
for(APIFootballMatch apiFootballMatch : apiFootballMatches) {
try {
TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatchesCopy);
tlwMatchesCopy.remove(tlwMatch);
tlwMatch.setShowTable(apiFootballMatch.getShowTable());
} catch (NullPointerException ignored) {
}
}
}
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() {
return this.tlwMatchesUpdated;
}
public String getBeautifulInfo() {

View File

@@ -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() {
return this.tlwMatchesUpdated;
}

View File

@@ -35,6 +35,8 @@ public class TippligaSQLConnector {
}
private TippligaSQLConnector() {
String databaseUsername = System.getenv("TLW_DATABASE_USERNAME");
String databasePassword = System.getenv("TLW_DATABASE_PASSWORD");
String jdbcUrlLocalhost = "jdbc:mysql://localhost:3306/d0144ddb" +
"?user=root" +
"&password=" +
@@ -44,8 +46,8 @@ public class TippligaSQLConnector {
"&serverTimezone=UTC" +
"&allowMultiQueries=true";
String jdbcUrlProd = "jdbc:mysql://w00f4eaf.kasserver.com:3306/d0144ddb" +
"?user=d0144ddb" +
"&password=TippligaWuerzb_1" +
"?user=" + databaseUsername +
"&password=" + databasePassword +
"&useUnicode=true" +
"&useJDBCCompliantTimezoneShift=true" +
"&useLegacyDatetimeCode=false" +

View File

@@ -1,5 +1,6 @@
package de.jeyp91.tippligaforum;
import de.jeyp91.tippliga.TLWMatch;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -24,9 +25,10 @@ public class TippligaWebsiteConnector {
CookieStore cookieStore = cm.getCookieStore();
private static final Logger logger = LogManager.getLogger(TippligaWebsiteConnector.class);
private final HttpClient client;
private final String username = "Julian";
private final String password = "original";
private final String username = System.getenv("FORUM_USERNAME");
private final String password = System.getenv("FORUM_PASSWORD");
private String lastCreationTime = "";
private String lastFormToken = "";
public TippligaWebsiteConnector() throws IOException {
CookieHandler.setDefault(cm);
@@ -37,7 +39,6 @@ public class TippligaWebsiteConnector {
.build();
login();
adminLogin();
updateResultsAdmin();
}
private void login() throws IOException {
@@ -57,8 +58,8 @@ public class TippligaWebsiteConnector {
Matcher matcher = pattern.matcher(reqBody);
matcher.find();
String creationTime = matcher.group(1);
String formToken = matcher.group(2);
this.lastCreationTime = matcher.group(1);
this.lastFormToken = matcher.group(2);
String sid = matcher.group(3);
Map<String, String> loginParameters = new HashMap<>();
@@ -68,8 +69,8 @@ public class TippligaWebsiteConnector {
loginParameters.put("viewonline", "on");
loginParameters.put("username", username);
loginParameters.put("password", password);
loginParameters.put("creation_time", creationTime);
loginParameters.put("form_token", formToken);
loginParameters.put("creation_time", this.lastCreationTime);
loginParameters.put("form_token", this.lastFormToken);
loginParameters.put("sid", sid);
String loginForm = loginParameters.entrySet()
@@ -113,8 +114,8 @@ public class TippligaWebsiteConnector {
Matcher matcher = pattern.matcher(reqBody);
matcher.find();
String creationTime = matcher.group(1);
String formToken = matcher.group(2);
this.lastCreationTime = matcher.group(1);
this.lastFormToken = matcher.group(2);
sid = matcher.group(3);
String credential = matcher.group(4);
@@ -123,8 +124,8 @@ public class TippligaWebsiteConnector {
loginParameters.put("redirect", "./../adm/index.php?sid=" + sid);
loginParameters.put("username", username);
loginParameters.put("password_" + credential, password);
loginParameters.put("creation_time", creationTime);
loginParameters.put("form_token", formToken);
loginParameters.put("creation_time", this.lastCreationTime);
loginParameters.put("form_token", this.lastFormToken);
loginParameters.put("sid", sid);
loginParameters.put("credential", credential);
@@ -150,7 +151,7 @@ public class TippligaWebsiteConnector {
List<HttpCookie> loginReqCookieList = cookieStore.getCookies();
}
private void updateResultsAdmin() {
public void updateResultsAdmin(int season, int league, int matchday, List<TLWMatch> matches) {
String sid = getSidFromCookie();
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.find();
String creationTime = matcher.group(1);
String formToken = matcher.group(2);
return;
}
this.lastCreationTime = matcher.group(1);
this.lastFormToken = matcher.group(2);
private void updateResults() {
Map<String, String> resultParameters = new HashMap<>();
resultParameters.put("s", "2023");
resultParameters.put("l", "2");
resultParameters.put("m", "32");
resultParameters.put("action", "result");
resultParameters.put("goalsh384", "4");
resultParameters.put("oldgoalsh384", "4");
resultParameters.put("goalsg384", "3");
resultParameters.put("oldgoalsg384", "4");
resultParameters.put("goalsh380", "");
resultParameters.put("oldgoalsh380", "");
resultParameters.put("goalsg380", "");
resultParameters.put("oldgoalsg380", "");
resultParameters.put("s", String.valueOf(season));
resultParameters.put("l", String.valueOf(league));
resultParameters.put("m", String.valueOf(matchday));
resultParameters.put("edit", "Speichern");
resultParameters.put("creation_time", this.lastCreationTime);
resultParameters.put("form_token", this.lastFormToken);
matches.forEach(tlwMatch -> {
String matchNo = String.valueOf(tlwMatch.getMatchNo());
resultParameters.put("select_" + matchNo, "on");
resultParameters.put("goals_home_" + matchNo, String.valueOf(tlwMatch.getGoalsHome()));
resultParameters.put("goals_guest_" + matchNo, String.valueOf(tlwMatch.getGoalsGuest()));
});
String resultForm = resultParameters.entrySet()
.stream()
@@ -197,7 +195,7 @@ public class TippligaWebsiteConnector {
.collect(Collectors.joining("&"));
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")
.POST(HttpRequest.BodyPublishers.ofString(resultForm))
.build();
@@ -209,8 +207,11 @@ public class TippligaWebsiteConnector {
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
matcher = pattern.matcher(resultReqBody);
matcher.find();
logger.info(resultReqBody);
this.lastCreationTime = matcher.group(1);
this.lastFormToken = matcher.group(2);
}
private String getSidFromCookie() {

View File

@@ -2,32 +2,12 @@ package de.jeyp91.tippliga;
import org.junit.Test;
public class TLWMatchesUpdaterFootballTest {
public class TLWMatchesResultsUpdaterTest {
@Test
public void getUpdateSqlTest1() {
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2022, 1, "Tippliga");
String sql = updater.getUpdateSQL();
// System.out.println(sql);
// System.out.println(updater.getBeautifulInfo());
}
@Test
public void getUpdateSqlTest2() {
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2021, 2, "Tippliga");
String sql = updater.getUpdateSQL();
// System.out.println(sql);
// System.out.println(updater.getBeautifulInfo());
}
@Test
public void getUpdateSqlTest48() {
TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2021, 48, "WTL-Pokal");
String sql = updater.getUpdateSQL();
// System.out.println(sql);
// System.out.println(updater.getBeautifulInfo());
public void updateResultsTest1() {
// TLWMatchesResultsUpdater updater = new TLWMatchesResultsUpdater(2023, 2, "Tippliga");
System.out.println("Done");
return;
}
}

View File

@@ -1,12 +1,21 @@
package de.jeyp91.tippligaforum;
import de.jeyp91.tippliga.TLWMatch;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class TippligaWebsiteConnectorTest {
@Test
public void getChecksumOfPostTest() throws IOException {
public void updateResultsAdminTest() throws IOException {
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);
}
}