Add auto update of results

This commit is contained in:
2023-06-06 15:45:25 +02:00
parent 7b721a5592
commit 4dcd994ac9
13 changed files with 275 additions and 74 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

@@ -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;
}
}

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

@@ -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;
}
}

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);
}
}