diff --git a/src/main/java/de/jeyp91/App.java b/src/main/java/de/jeyp91/App.java index 06c8deb..1463740 100644 --- a/src/main/java/de/jeyp91/App.java +++ b/src/main/java/de/jeyp91/App.java @@ -5,9 +5,10 @@ import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.ThreadContext; +import org.apache.logging.log4j.core.config.Configurator; /** * Hello world! @@ -22,13 +23,15 @@ public class App { private static Logger logger = LogManager.getLogger(App.class); public static void main(String[] args) throws Exception { - ThreadContext.put("myLogLvl", "INFO"); + Configurator.setRootLevel(Level.INFO); initOptions(args); String sql = ""; + String beautifulInfo = ""; switch(mode) { case "MatchdaysUpdater": TLWMatchdaysUpdater matchdaysUpdater = new TLWMatchdaysUpdater(season, league, configFile); sql = matchdaysUpdater.getUpdateSql(); + beautifulInfo = matchdaysUpdater.getBeautifulInfo(); break; case "MatchesCreatorFootball": TLWMatchesCreatorFootball creator = new TLWMatchesCreatorFootball(season, league, configFile); @@ -37,6 +40,7 @@ public class App { case "MatchesUpdaterFootball": TLWMatchesUpdaterFootball tlwMatchesUpdaterFootball = new TLWMatchesUpdaterFootball(season, league, configFile); sql = tlwMatchesUpdaterFootball.getUpdateSQL(); + beautifulInfo = tlwMatchesUpdaterFootball.getBeautifulInfo(); break; case "TeamsUpdater": TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile); @@ -47,17 +51,11 @@ public class App { default: break; } - if (sql.equals("")) { - logger.info("No updates for season " + season + ", league " + league + ", config " + configFile); - } else { - logger.info("Executed query:\n" + sql); - } if(!StatusHolder.getError() && !sql.equals("")) { TippligaSQLConnector con = new TippligaSQLConnector(); // con.executeUpdate(sql); + logger.info(beautifulInfo); } - logger.error("testerror"); - logger.info("testinfo"); if(StatusHolder.getError()) { System.exit(1); } diff --git a/src/main/java/de/jeyp91/BaseMatch.java b/src/main/java/de/jeyp91/BaseMatch.java index 0a1c336..11d5b70 100644 --- a/src/main/java/de/jeyp91/BaseMatch.java +++ b/src/main/java/de/jeyp91/BaseMatch.java @@ -9,6 +9,8 @@ public abstract class BaseMatch { protected Integer teamIdHome; protected Integer teamIdGuest; + protected String teamNameHome = null; + protected String teamNameGuest = null; protected Integer goalsHome = null; protected Integer goalsGuest = null; protected Integer matchday = null; @@ -37,4 +39,12 @@ public abstract class BaseMatch { public Integer getGoalsGuest() { return this.goalsGuest; } + + public String getTeamNameHome() { + return this.teamNameHome; + } + + public String getTeamNameGuest() { + return this.teamNameGuest; + } } diff --git a/src/main/java/de/jeyp91/TeamIDMatcher.java b/src/main/java/de/jeyp91/TeamIDMatcher.java index 5c550f1..5bae3c8 100644 --- a/src/main/java/de/jeyp91/TeamIDMatcher.java +++ b/src/main/java/de/jeyp91/TeamIDMatcher.java @@ -1,11 +1,6 @@ package de.jeyp91; -import java.io.IOException; -import java.net.URL; -import java.nio.charset.StandardCharsets; - import com.google.common.collect.HashBiMap; -import com.google.common.io.Resources; import de.jeyp91.gists.GistProvider; import org.apache.logging.log4j.*; import org.json.simple.JSONArray; @@ -14,28 +9,31 @@ import org.json.simple.JSONObject; public class TeamIDMatcher { private static HashBiMap ids = null; - private static Logger logger = LogManager.getLogger(TeamIDMatcher.class); + private static final Logger logger = LogManager.getLogger(TeamIDMatcher.class); + private static JSONArray teams; + private static boolean init = false; private static void initBiMap() { - ids = HashBiMap.create(); - GistProvider prov = GistProvider.getInstance(); - JSONArray teams = prov.getTeamIdMatcher(); - - for(Object team:teams) { - int tippligaID = ((Long)((JSONObject) team).get("tippligaID")).intValue(); - int openligaDBID = ((Long) ((JSONObject) team).get("apiFootballID")).intValue(); - ids.put(tippligaID, openligaDBID); + if(!init) { + ids = HashBiMap.create(); + GistProvider prov = GistProvider.getInstance(); + teams = prov.getTeamIdMatcher(); + + for (Object team : teams) { + int tippligaID = ((Long) ((JSONObject) team).get("tippligaID")).intValue(); + int apiFootballID = ((Long) ((JSONObject) team).get("apiFootballID")).intValue(); + ids.put(tippligaID, apiFootballID); + } + init = true; } } public static Integer getApiFootballIdFromTippligaId(int id) { - if(ids == null) { - initBiMap(); - } + initBiMap(); if(ids.containsKey(id)) { return ids.get(id); } else { - logger.error("Tippliga ID: " + String.valueOf(id) + " not in ID Matcher."); + logger.error("Tippliga ID: " + id + " not in ID Matcher."); StatusHolder.setError(); return null; } @@ -43,15 +41,26 @@ public class TeamIDMatcher { public static Integer getTippligaIdFromApiFootballId(Integer id) { if(id == null) return null; - if(ids == null) { - initBiMap(); - } + initBiMap(); if(ids.inverse().containsKey(id)) { return ids.inverse().get(id); } else { - logger.error("API Football ID: " + String.valueOf(id) + " not in ID Matcher."); + logger.error("API Football ID: " + id + " not in ID Matcher."); StatusHolder.setError(); return null; } } + + public static String getTeamNameFromTippligaId(Integer id) { + initBiMap(); + String name = ""; + for(Object team:teams) { + int tippligaID = ((Long)((JSONObject) team).get("tippligaID")).intValue(); + if(id == tippligaID) { + name = (((JSONObject) team).get("teamname")).toString(); + break; + } + } + return name; + } } \ No newline at end of file diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatch.java b/src/main/java/de/jeyp91/tippliga/TLWMatch.java index a0a363b..aaa47a8 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatch.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatch.java @@ -125,6 +125,8 @@ public class TLWMatch extends BaseMatch{ this.formulaGuest = ""; this.status = status; this.koMatch = koMatch; + this.teamNameHome = apiFootballMatch.getTeamNameHome(); + this.teamNameGuest = apiFootballMatch.getTeamNameGuest(); } public TLWMatch(int season, int league, int matchday, int matchNo, String matchDatetime, int status, int koMatch) { diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatchdaysUpdater.java b/src/main/java/de/jeyp91/tippliga/TLWMatchdaysUpdater.java index f3816e1..f38107c 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatchdaysUpdater.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatchdaysUpdater.java @@ -1,7 +1,5 @@ package de.jeyp91.tippliga; -import org.json.simple.JSONObject; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -14,6 +12,7 @@ public class TLWMatchdaysUpdater { int league; ArrayList matchdaysOriginal; ArrayList matchdaysUpdated; + String beautifulInfo = ""; public TLWMatchdaysUpdater(int season, int league, String configPath) throws ParseException { this.season = season; @@ -58,27 +57,40 @@ public class TLWMatchdaysUpdater { String condition = "WHERE season = " + matchdayOriginal.getSeason() + " " + "AND league = " + matchdayOriginal.getLeague() + " " + "AND matchday = " + matchdayOriginal.getMatchday() + ";\n"; + String beautifulInfoStart = "Aktualisiere Saison " + matchdayOriginal.getSeason() + ", " + + "Liga " + matchdayOriginal.getLeague() + ", " + + "Spieltag " + matchdayOriginal.getMatchday() + ", "; if (!matchdayOriginal.getDeliveryDate().equals(matchdayUpdated.getDeliveryDate())) { updateSql += updateStart + "delivery_date = '" + matchdayUpdated.getDeliveryDate() + "' " + condition; + this.beautifulInfo += beautifulInfoStart + + "Tippabgabeschluss 1 zu '" + matchdayUpdated.getDeliveryDate() + "'.\n"; } if (!matchdayOriginal.getDeliveryDate2().equals(matchdayUpdated.getDeliveryDate2())) { updateSql += updateStart + "delivery_date_2 = '" + matchdayUpdated.getDeliveryDate2() + "' " + condition; + this.beautifulInfo += beautifulInfoStart + + "Tippabgabeschluss 2 zu '" + matchdayUpdated.getDeliveryDate2() + "'.\n"; } if (!matchdayOriginal.getMatchdayName().equals(matchdayUpdated.getMatchdayName())) { updateSql += updateStart + "matchday_name = '" + matchdayUpdated.getMatchdayName() + "' " + condition; + this.beautifulInfo += beautifulInfoStart + + "Spieltagsname zu '" + matchdayUpdated.getMatchdayName() + "'.\n"; } } } return updateSql; } + + public String getBeautifulInfo() { + return this.beautifulInfo; + } } diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java b/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java index 7a2e9f0..baf755b 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.Logger; import org.json.simple.JSONArray; import org.json.simple.JSONObject; +import javax.sound.midi.SysexMessage; import java.time.*; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -21,8 +22,9 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase { ArrayList tlwMatchesOriginal; ArrayList tlwMatchesUpdated; - public TLWMatchesUpdaterFootball(int season, int league, String configFileName) { + String beautifulInfo = ""; + public TLWMatchesUpdaterFootball(int season, int league, String configFileName) { this.season = season; this.league = league; @@ -79,29 +81,42 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase { "AND league = " + matchOriginal.getLeague() + " " + "AND matchday = " + matchOriginal.getMatchday() + " " + "AND match_no = " + matchOriginal.getMatchNo() + ";\n"; + 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() != matchUpdated.getTeamIdHome()) { updateString += updateStart + "team_id_home = " + matchUpdated.getTeamIdHome() + " " + condition; + this.beautifulInfo += beautifulInfoStart + + "Heimteam zu '" + matchUpdated.getTeamNameHome() + "'.\n"; } if(matchOriginal.getTeamIdGuest() != matchUpdated.getTeamIdGuest()) { updateString += updateStart + "team_id_guest = " + matchUpdated.getTeamIdGuest() + " " + condition; + this.beautifulInfo += beautifulInfoStart + + "Gastteam zu '" + matchUpdated.getTeamNameGuest() + "'.\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"; } @@ -150,7 +165,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase { if(earliestDate.isAfter(now)) { for(TLWMatch match : matches) { LocalDateTime date = TLWMatchesManagerBase.getDate(match); - if (this.getDaysDifference(earliestDate, date) == 0) { + if (getDaysDifference(earliestDate, date) == 0) { match.setStatus(0); } else { match.setStatus(-1); @@ -182,4 +197,8 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase { public ArrayList getTLWMatchesUpdated() { return this.tlwMatchesUpdated; } + + public String getBeautifulInfo() { + return this.beautifulInfo; + } } diff --git a/src/main/java/de/jeyp91/tippliga/TippligaSQLConnector.java b/src/main/java/de/jeyp91/tippliga/TippligaSQLConnector.java index 84a3fdc..22ca24d 100644 --- a/src/main/java/de/jeyp91/tippliga/TippligaSQLConnector.java +++ b/src/main/java/de/jeyp91/tippliga/TippligaSQLConnector.java @@ -87,12 +87,12 @@ public class TippligaSQLConnector { } public ArrayList getMatches(String season, String league) { - String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE `season` = " + season + " AND `league` = " + league + ";"; + String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE `season` = " + season + " AND `league` = " + league + " ORDER BY match_no ASC;"; return getMatches(queryString); } public ArrayList getMatches(String season, String league, String matchday) { - String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE `season` = " + season + " AND `league` = " + league + " AND `matchday` = " + matchday + ";"; + String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE `season` = " + season + " AND `league` = " + league + " AND `matchday` = " + matchday + " ORDER BY match_no ASC;"; return getMatches(queryString); } diff --git a/src/test/java/de/jeyp91/tippliga/TLWMatchdayUpdaterTest.java b/src/test/java/de/jeyp91/tippliga/TLWMatchdayUpdaterTest.java index 8982d35..e578558 100644 --- a/src/test/java/de/jeyp91/tippliga/TLWMatchdayUpdaterTest.java +++ b/src/test/java/de/jeyp91/tippliga/TLWMatchdayUpdaterTest.java @@ -11,6 +11,7 @@ public class TLWMatchdayUpdaterTest { String sql = matchdaysUpdater.getUpdateSql(); System.out.println(sql); + System.out.println(matchdaysUpdater.getBeautifulInfo()); } @Test @@ -20,5 +21,6 @@ public class TLWMatchdayUpdaterTest { String sql = matchdaysUpdater.getUpdateSql(); System.out.println(sql); + System.out.println(matchdaysUpdater.getBeautifulInfo()); } } diff --git a/src/test/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootballTest.java b/src/test/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootballTest.java index 6281bf6..82fdeeb 100644 --- a/src/test/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootballTest.java +++ b/src/test/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootballTest.java @@ -5,18 +5,20 @@ import org.junit.Test; public class TLWMatchesUpdaterFootballTest { @Test - public void getUpdateSqlTest1() throws Exception { + public void getUpdateSqlTest1() { TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2021, 1, "Tippliga.json"); String sql = updater.getUpdateSQL(); System.out.println(sql); + System.out.println(updater.getBeautifulInfo()); } @Test - public void getUpdateSqlTest2() throws Exception { + public void getUpdateSqlTest2() { TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2021, 2, "Tippliga.json"); String sql = updater.getUpdateSQL(); System.out.println(sql); + System.out.println(updater.getBeautifulInfo()); } } diff --git a/tokens/StoredCredential b/tokens/StoredCredential index 91db770..3298061 100644 Binary files a/tokens/StoredCredential and b/tokens/StoredCredential differ